Skip to content
This repository was archived by the owner on Nov 27, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,23 @@ MCP server providing Example API functionality via FastMCP.
src/mcp_example/
├── server.py # MCP tools (FastMCP) + entrypoints
├── api_client.py # Async HTTP client for Example API
└── api_models.py # Pydantic models for API responses
├── api_models.py # Pydantic models for API responses
└── skills/
└── example/
└── SKILL.md # The skill served at skill://example/SKILL.md
```

## Server SDK

The server is built on `nimblebrain-server-sdk` ([quickstart](https://docs.nimblebrain.ai/server-sdk/quickstart/)).
Use it instead of writing these by hand:

- **Annotations**: every tool carries `READS`, `ADDS` or `CHANGES` (`@mcp.tool(annotations=READS)`). A tool with none reads to a client as a destructive write.
- **Errors**: a tool returns a failure with `to_tool_error(ServiceError(ErrorCode.X, "..."))` from `nimblebrain_server_sdk.errors`. Never return a dict that describes an error, and never raise `ValueError` for a caller's mistake. Classify an API failure with `ServiceError.from_upstream(status, detail=...)`; the API's own text goes in `detail` (logged), never in the message. ([Errors](https://docs.nimblebrain.ai/server-sdk/errors/))
- **Skills**: a skill is a directory under `skills/` whose name equals the `name` in its `SKILL.md` frontmatter, registered in the one `add_skills(mcp, [...])` call. Do not serve a `skill://` resource by hand. ([Skills](https://docs.nimblebrain.ai/server-sdk/skills/))
- **Listings**: a listing tool builds each row with `listing_row`, with a `uri` and a preview in place of any unbounded text field. The `uri` must resolve: a resource template (`example://items/{item_id}`) returns the whole record.
- **Tests**: run each test that crosses the wire on both protocol versions (`Client(mcp, mode="auto")` and `mode="legacy"`), check skills with `served_skills` and listing rows with `assert_bounded_rows`. ([Testing](https://docs.nimblebrain.ai/server-sdk/testing/))

## Critical

- Package name: `@nimblebraininc/example` (npm-style scope, matches GitHub org)
Expand All @@ -22,7 +36,7 @@ src/mcp_example/
mcp.run() # Stdio for Claude Desktop / mpak
```
- All logs to stderr (stdout is reserved for JSON-RPC)
- A failure the caller must see is a raised `ToolError`; never log to the client with `ctx.info`/`ctx.error` (MCP's logging capability is deprecated as of 2026-07-28, SEP-2577)
- A failure the caller must see is returned with `to_tool_error`; never log to the client with `ctx.info`/`ctx.error` (MCP's logging capability is deprecated as of 2026-07-28, SEP-2577)

## user_config

Expand Down Expand Up @@ -90,6 +104,7 @@ GitHub Actions builds and uploads MCPB bundles automatically on release.

1. Add response model to `api_models.py`
2. Add client method to `api_client.py`
3. Add `@mcp.tool()` function to `server.py`
4. Add tests to `tests/`
5. Run `make check` to verify
3. Add `@mcp.tool(annotations=...)` function to `server.py`
4. Add a row for the tool to `skills/example/SKILL.md`
5. Add tests to `tests/`
6. Run `make check` to verify
12 changes: 7 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,17 @@ npx skills add nimblebraininc/skills --skill mcpb --agent claude-code -y

1. **Add response models** to `src/mcp_example/api_models.py`
2. **Add client methods** to `src/mcp_example/api_client.py`
3. **Add the tool** to `src/mcp_example/server.py` using `@mcp.tool()`
4. **Add tests** to `tests/`
5. **Run checks**: `make check`
3. **Add the tool** to `src/mcp_example/server.py` using `@mcp.tool(annotations=...)`
4. **Describe the tool** in `src/mcp_example/skills/example/SKILL.md`
5. **Add tests** to `tests/`, run on both protocol versions
6. **Run checks**: `make check`

### Tool Design Guidelines

- One tool per API operation (`list_items`, `get_item`, `create_item`)
- Clear docstrings with Args/Returns sections
- Report a failure the caller must see by raising `ToolError` (from `fastmcp.exceptions`) with a message safe to show, and log diagnostics to stderr with the `logging` module. Do not send logs to the client (`ctx.info`, `ctx.error`): MCP's logging capability is deprecated as of the 2026-07-28 protocol (SEP-2577)
- Annotate every tool with `READS`, `ADDS` or `CHANGES` from `nimblebrain_server_sdk`
- Report a failure the caller must see by returning `to_tool_error(ServiceError(ErrorCode.X, "..."))` (from `nimblebrain_server_sdk.errors`) with a message safe to show, and log diagnostics to stderr with the `logging` module. See the [errors guide](https://docs.nimblebrain.ai/server-sdk/errors/). Do not send logs to the client (`ctx.info`, `ctx.error`): MCP's logging capability is deprecated as of the 2026-07-28 protocol (SEP-2577)
- Return Pydantic models, not raw dicts

### Code Quality
Expand Down Expand Up @@ -89,6 +91,6 @@ Or simply: `make check`
- MTF scanner passes (no critical/high findings)

### For Companion Skills
- SKILL.md with complete frontmatter
- A directory under `src/mcp_example/skills/` named after the skill, holding a `SKILL.md` whose frontmatter has that `name` and a `description`, registered with `add_skills`
- Composes 2+ tools into a workflow
- At least 2 usage examples
97 changes: 95 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ An MCP (Model Context Protocol) server that provides access to the Example API,
- List and retrieve items from the Example API
- Async HTTP client with error handling
- Typed responses with Pydantic models
- Built on the [NimbleBrain server SDK](#built-on-the-nimblebrain-server-sdk): annotated tools, classified errors, and a skill served to the host

## Installation

Expand Down Expand Up @@ -64,8 +65,100 @@ Add to your `~/.claude/settings.json`:

| Tool | Description |
|------|-------------|
| `list_items` | List items from the API with optional limit |
| `get_item` | Get a single item by its ID |
| `list_items` | List items from the API with optional limit. Each row carries a `uri` and a preview of the description |
| `get_item` | Get a single item, whole, by its ID |

Both tools read and change nothing, and say so with the `READS` annotation. A row's `uri`
(`example://items/<id>`) is a resource that returns the whole item as JSON. The server also
serves one skill, `skill://example/SKILL.md`, which tells an agent when to use each tool.

## Built on the NimbleBrain server SDK

The server uses [`nimblebrain-server-sdk`](https://pypi.org/project/nimblebrain-server-sdk/)
for what every server on NimbleBrain shares. Start with the
[quickstart](https://docs.nimblebrain.ai/server-sdk/quickstart/).

| The server does this | With | Guide |
|---|---|---|
| Declares what each tool can change | `READS`, `ADDS`, `CHANGES` | [Quickstart](https://docs.nimblebrain.ai/server-sdk/quickstart/) |
| Returns a failure with a code the caller can act on | `to_tool_error`, `ServiceError`, `ErrorCode` | [Errors](https://docs.nimblebrain.ai/server-sdk/errors/) |
| Serves the skill in `src/mcp_example/skills/` | `add_skills` | [Skills](https://docs.nimblebrain.ai/server-sdk/skills/) |
| Tests what a host sees, on both protocol versions | `served_skills`, `assert_bounded_rows` | [Testing](https://docs.nimblebrain.ai/server-sdk/testing/) |

### A tool

A tool carries one annotation: `READS`, `ADDS` (a write that loses nothing) or `CHANGES` (a
write that overwrites or removes). It returns a failure with `to_tool_error`; it does not
return a dict that describes the error, and it does not raise for a caller's mistake.

```python
from fastmcp import FastMCP
from nimblebrain_server_sdk import ADDS
from nimblebrain_server_sdk.errors import ErrorCode, ServiceError, to_tool_error

mcp = FastMCP("Example")

ITEMS: dict[str, str] = {}


@mcp.tool(annotations=ADDS)
async def create_item(name: str) -> dict[str, str]:
"""Create an item and return it."""
if not name.strip():
return to_tool_error(ServiceError(ErrorCode.BAD_INPUT, "`name` is empty."))
item_id = str(len(ITEMS) + 1)
ITEMS[item_id] = name
return {"id": item_id, "name": name}
```

The caller of `create_item` with an empty name receives an error result whose structured
content is `{"error": {"code": "bad_input", "retryable": false, "message": "`name` is empty."}}`.

### A skill

A skill is a directory that holds a `SKILL.md`. The frontmatter needs a `name` and a
`description`, and `name` must equal the directory's name. `add_skills` checks every skill
when the server is imported and serves each at `skill://<name>/SKILL.md`:

```python
from pathlib import Path

from fastmcp import FastMCP
from nimblebrain_server_sdk import add_skills

mcp = FastMCP("Example")
add_skills(mcp, [Path("src/mcp_example/skills/example")])
```

### A test

A host connects on one of two protocol versions, so a test runs on both:
`Client(mcp, mode="auto")` negotiates 2026-07-28 and `mode="legacy"` runs the 2025-11-25
handshake. `served_skills` reads every skill file back the way a host does.

```python
import pytest
from fastmcp import Client
from nimblebrain_server_sdk.testing import served_skills

from mcp_example.server import mcp


@pytest.mark.parametrize("mode", ["auto", "legacy"])
async def test_the_skill_is_served(mode):
skills = await served_skills(mcp, mode)
assert set(skills) == {"skill://example/SKILL.md"}


@pytest.mark.parametrize("mode", ["auto", "legacy"])
async def test_an_empty_item_id_is_bad_input(mode):
async with Client(mcp, mode=mode) as client:
result = await client.call_tool("get_item", {"item_id": " "}, raise_on_error=False)
assert result.is_error
assert result.structured_content["error"]["code"] == "bad_input"
```

`tests/test_server.py` holds the full set.

## Development

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ classifiers = [
dependencies = [
"aiohttp>=3.11.0",
"fastmcp>=4.0.0",
"nimblebrain-server-sdk>=0.6.1",
"pydantic>=2.0.0",
"python-dotenv>=1.0.0",
]
Expand Down
18 changes: 0 additions & 18 deletions src/mcp_example/SKILL.md

This file was deleted.

Loading
Loading