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
23 changes: 12 additions & 11 deletions .github/ISSUE_TEMPLATE/new-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,24 @@ assignees: ''

```bash
# 1. Install the build skill
npx skills add nimblebraininc/skills --skill mcpb --agent claude-code -y
npx skills add nimblebraininc/skills --skill mcp-server --agent claude-code -y

# 2. Create repo from template
gh repo create NimbleBrainInc/mcp-<name> --template NimbleBrainInc/mcp-server-template --public --clone
# 2. Create the repo from the template
gh repo create NimbleBrainInc/mcp-<name> --template NimbleBrainInc/mcp-server-template-python --public --clone

# 3. Run /mcpb — scaffolds the server, implements tools, validates the
# bundle (MTF scan), and authors companion skills, end to end
# 3. Ask your agent to build the server with the mcp-server skill: it proposes
# the tools, implements and tests them, serves the server with its Server
# Card, and writes server.json

# 4. Iterate with `make check` as you build
```

## Definition of Done

- [ ] 5+ tools implemented
- [ ] manifest.json valid (v0.4)
- [ ] 5+ tests passing
- [ ] CI passing
- [ ] MTF scanner passes
- [ ] 2+ companion skills validated
- [ ] Tools designed with the `mcp-server` skill, each annotated and failing through the error contract
- [ ] Tests for each tool's success and failure paths, on both protocol versions
- [ ] `server.json` names the deployed URL and agrees with the Server Card
- [ ] CI workflow passing (format, lint, typecheck, test, bundle)
- [ ] Security Scan workflow passing (no critical or high findings)
- [ ] Companion skills served with `add_skills`
- [ ] PR submitted and reviewed
6 changes: 6 additions & 0 deletions .github/workflows/build-bundle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ jobs:
run: |
VERSION="${{ github.event.release.tag_name }}"
VERSION="${VERSION#v}"
# The Server Card reports __version__, which only `make bump` moves.
PKG_VERSION=$(sed -n 's/^__version__ = "\(.*\)"$/\1/p' src/mcp_example/__init__.py)
if [ "$VERSION" != "$PKG_VERSION" ]; then
echo "::error::Tag version $VERSION differs from __version__ $PKG_VERSION; run make bump before tagging."
exit 1
fi
jq --arg v "$VERSION" '.version = $v' manifest.json > manifest.tmp.json
mv manifest.tmp.json manifest.json
if [ -f server.json ]; then
Expand Down
23 changes: 22 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ Use it instead of writing these by hand:
- **Errors**: a tool reports a failure by raising `ServiceError(ErrorCode.X, "...")` from `nimblebrain_server_sdk.errors`. `add_error_contract(mcp)`, called once where the server is built, returns it to the caller as an error result with its code. Never return a dict that describes an error (a host and a model score it as a success), 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.
- **Server Card**: `add_server_card(mcp, title=..., description=...)` serves the card a host reads before it connects, at `<mcp-url>/server-card`. `name` and `version` come from `FastMCP("com.example/example", version=__version__)`: the name is reverse-DNS with one slash, and `version=` is required (without it FastMCP reports its own version). A connector passes no `placements`; an app's server passes them for its `ui://` views. ([Server Card](https://docs.nimblebrain.ai/server-sdk/server-card/))
- **Tests**: run each test that crosses the wire on both protocol versions (`Client(mcp, mode="auto")` and `mode="legacy"`), annotate the parametrized `mode` with `Mode` from `nimblebrain_server_sdk.testing`, 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)
- Bundle name: `@nimblebraininc/example` in `manifest.json` (npm-style scope, matches GitHub org)
- Server name: `com.example/example` (reverse-DNS), the same in `FastMCP(...)` and `server.json`
- Manifest uses module execution: `python -m mcp_example.server`
- Server needs both entrypoints:
```python
Expand All @@ -38,6 +40,18 @@ Use it instead of writing these by hand:
- All logs to stderr (stdout is reserved for JSON-RPC)
- A failure the caller must see is a raised `ServiceError`; never log to the client with `ctx.info`/`ctx.error` (MCP's logging capability is deprecated as of 2026-07-28, SEP-2577)

## server.json

`server.json` is an MCP Registry `ServerDetail` (`$schema` names the 2025-12-11
`server.schema.json`): what an operator adds to a deployed NimbleBrain's connectors catalog
and what `mcp-publisher` lists on the official MCP Registry. It restates the Server Card's
`name`, `title`, `description` and `version`, and adds `remotes`, the deployed
streamable-HTTP URL (a placeholder until the server is deployed). `tests/test_server_card.py`
holds it equal to the served card.

- A connector carries no `_meta`. An app adds `_meta["ai.nimblebrain/host"]` with the card's placements.
- Add `packages` only once the server is published to PyPI; the bundle release does not publish one.

## user_config

API key configured via manifest `user_config`, not hardcoded:
Expand Down Expand Up @@ -74,8 +88,13 @@ uv run ruff check src/ tests/ # Lint
uv run ty check src/ # Type check
uv run pytest tests/ -v # Test
make check # All of the above
make run-http # Serve at http://127.0.0.1:8000/mcp (card at /mcp/server-card)
```

`make run-http` binds loopback. On Linux, a NimbleBrain running in Docker reaches the host
through the Docker bridge: `make run-http HOST=172.17.0.1`, or `HOST=0.0.0.0`, which also
exposes the server to the network.

## Version Management

Version lives in four files that MUST stay in sync:
Expand All @@ -102,6 +121,8 @@ GitHub Actions builds and uploads MCPB bundles automatically on release.

## Adding New Tools

Design the tool first with the `mcp-server` skill (`npx skills add nimblebraininc/skills --skill mcp-server --agent claude-code -y`), then:

1. Add response model to `api_models.py`
2. Add client method to `api_client.py`
3. Add `@mcp.tool(annotations=...)` function to `server.py`
Expand Down
26 changes: 16 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,34 @@ make check

### Recommended Claude Code Skill

The `mcpb` skill builds a server from this template end to end:
The `mcp-server` skill builds a server from this template end to end: it designs the tools
before code, implements them with `nimblebrain-server-sdk`, tests them, serves the server over
HTTP with its Server Card, and writes `server.json`. It also reviews an existing server's tools.

```bash
npx skills add nimblebraininc/skills --skill mcpb --agent claude-code -y
npx skills add nimblebraininc/skills --skill mcp-server --agent claude-code -y
```

## Development Workflow

### Adding a New Tool

Design the tool before writing it, the way the `mcp-server` skill does: a name and a
description that say when to call it, a `description` on every parameter, bounded results,
and one annotation. Then:

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(annotations=...)`
4. **Describe the tool** in `src/mcp_example/skills/example/SKILL.md`
5. **Add tests** to `tests/`, run on both protocol versions
5. **Add tests** to `tests/`, run on both protocol versions: the success path and each failure, checking the error code
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
- Annotate every tool with `READS`, `ADDS` or `CHANGES` from `nimblebrain_server_sdk`
- Annotate every tool with `READS` (reads and changes nothing), `ADDS` (writes without losing anything) or `CHANGES` (overwrites, removes, sends) from `nimblebrain_server_sdk`. A tool with no annotation reads to a host as a destructive write
- Report a failure the caller must see by raising `ServiceError(ErrorCode.X, "...")` (from `nimblebrain_server_sdk.errors`) with a message safe to show; `add_error_contract(mcp)` returns it to the caller as an error result. Never return an error as a plain dict: a host and a model score it as a success. 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

Expand All @@ -70,7 +76,7 @@ Or simply: `make check`
2. Make your changes
3. Run `make check` and fix any issues
4. Push and create a PR
5. CI must pass (lint, typecheck, test, bundle)
5. CI must pass: the CI workflow (format, lint, typecheck, test, bundle) and the Security Scan workflow (`mpak-scanner` on the built bundle, failing on any critical or high finding)

### PR Checklist

Expand All @@ -83,11 +89,11 @@ Or simply: `make check`
## Definition of Done

### For MCP Servers
- 5+ tools implemented
- manifest.json valid (v0.4)
- 5+ tests passing
- CI/CD workflow passing
- MTF scanner passes (no critical/high findings)
- Tools designed with the `mcp-server` skill, each annotated and failing through the error contract
- Tests for each tool's success and failure paths, on both protocol versions
- `server.json` names the deployed URL and agrees with the Server Card (`tests/test_server_card.py`)
- The CI workflow passes: format, lint, typecheck, test, and `mcpb pack` (which validates `manifest.json`)
- The Security Scan workflow passes: no critical or high `mpak-scanner` findings

### For Companion Skills
- 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`
Expand Down
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# MCPB bundle configuration
BUNDLE_NAME = mcp-example
VERSION ?= 0.1.0
# run-http binds loopback. On Linux, a NimbleBrain in Docker reaches the host through the
# Docker bridge: HOST=172.17.0.1, or HOST=0.0.0.0, which also exposes the server to the network.
HOST ?= 127.0.0.1
PORT ?= 8000

.PHONY: help install dev-install format format-check lint lint-fix typecheck test test-integration test-llm test-cov clean run run-http check all bump bundle

Expand Down Expand Up @@ -57,8 +61,8 @@ clean: ## Clean up build artifacts and cache
run: ## Run the MCP server in stdio mode
uv run python -m mcp_example.server

run-http: ## Run the MCP server in HTTP mode
uv run uvicorn mcp_example.server:app --host 0.0.0.0 --port 8000
run-http: ## Run the MCP server over HTTP at http://$(HOST):$(PORT)/mcp (HOST defaults to 127.0.0.1)
uv run uvicorn mcp_example.server:app --host $(HOST) --port $(PORT)

check: format-check lint typecheck test ## Run all checks

Expand Down
45 changes: 42 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +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
- Built on the [NimbleBrain server SDK](#built-on-the-nimblebrain-server-sdk): annotated tools, classified errors, a skill served to the host, and a Server Card

## Installation

Expand Down Expand Up @@ -83,6 +83,7 @@ for what every server on NimbleBrain shares. Start with the
| 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 | `add_error_contract`, `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/) |
| Names and describes itself to a host before it connects | `add_server_card` | [Server Card](https://docs.nimblebrain.ai/server-sdk/server-card/) |
| Tests what a host sees, on both protocol versions | `Mode`, `served_skills`, `assert_bounded_rows` | [Testing](https://docs.nimblebrain.ai/server-sdk/testing/) |

### A tool
Expand All @@ -98,7 +99,7 @@ from fastmcp import FastMCP
from nimblebrain_server_sdk import ADDS, add_error_contract
from nimblebrain_server_sdk.errors import ErrorCode, ServiceError

mcp = FastMCP("Example")
mcp = FastMCP("com.example/example", version="0.1.0")
add_error_contract(mcp)

ITEMS: dict[str, str] = {}
Expand Down Expand Up @@ -129,7 +130,7 @@ from pathlib import Path
from fastmcp import FastMCP
from nimblebrain_server_sdk import add_skills

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

Expand Down Expand Up @@ -164,6 +165,37 @@ async def test_an_empty_item_id_is_bad_input(mode: Mode) -> None:

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

### A Server Card

A host that has only the server's URL reads its Server Card, at `<mcp-url>/server-card`,
to name and describe it before it connects. `name` and `version` come from the `FastMCP`
constructor, so the server is named in reverse-DNS form and given its own version (without
`version=`, FastMCP reports its own). `title` and `description` are 1 to 100 characters:

```python
from fastmcp import FastMCP
from nimblebrain_server_sdk import add_server_card

from mcp_example import __version__

mcp = FastMCP("com.example/example", version=__version__)
add_server_card(mcp, title="Example", description="List and read items from the Example API.")
```

The card is served over streamable HTTP only: `make run-http`, then
`curl -s http://127.0.0.1:8000/mcp/server-card`. This server is a connector, so the card has
no `placements`; an app's server passes them for its `ui://` views.

## Deploying: server.json

`server.json` is an [MCP Registry `ServerDetail`](https://github.com/modelcontextprotocol/registry/blob/main/docs/reference/server-json/generic-server-json.md):
what an operator adds to a deployed NimbleBrain's
[connectors catalog](https://docs.nimblebrain.ai/config/connectors-catalog/), and what
`mcp-publisher` lists on the official MCP Registry. It restates the card's `name`, `title`,
`description` and `version`, and adds `remotes`, the URL the server is deployed at. Replace
the placeholder `https://mcp.example.com/mcp` with yours. `tests/test_server_card.py` fails
when `server.json` and the served card disagree, and `make bump` moves both versions together.

## Development

```bash
Expand All @@ -184,8 +216,15 @@ uv run ty check src/

# Run all checks
make check

# Serve over HTTP at http://127.0.0.1:8000/mcp
make run-http
```

`make run-http` binds loopback. On Linux, a NimbleBrain running in Docker reaches the host
through the Docker bridge: `make run-http HOST=172.17.0.1`, or `HOST=0.0.0.0`, which also
exposes the server to the network.

## License

MIT
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ classifiers = [
dependencies = [
"aiohttp>=3.11.0",
"fastmcp>=4.0.0",
"nimblebrain-server-sdk>=0.7,<0.8",
"nimblebrain-server-sdk>=0.8,<0.9",
"pydantic>=2.0.0",
"python-dotenv>=1.0.0",
]
Expand Down
18 changes: 14 additions & 4 deletions server.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
{
"name": "@nimblebraininc/example",
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
"name": "com.example/example",
"title": "Example",
"description": "List and read items from the Example API.",
"version": "0.1.0",
"description": "MCP server for the Example API",
"publisher": "nimblebraininc",
"repository": "https://github.com/NimbleBrainInc/mcp-example"
"repository": {
"url": "https://github.com/NimbleBrainInc/mcp-example",
"source": "github"
},
"remotes": [
{
"type": "streamable-http",
"url": "https://mcp.example.com/mcp"
}
]
}
18 changes: 15 additions & 3 deletions src/mcp_example/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

Getting started:
1. Rename this package from mcp_example to mcp_<yourservice>
2. Update manifest.json, server.json, pyproject.toml with your service info
2. Update manifest.json, server.json, pyproject.toml with your service info, and the
server's name, TITLE and DESCRIPTION below (server.json restates them)
3. Implement your API client in api_client.py
4. Add Pydantic models in api_models.py
5. Add tools below using @mcp.tool(annotations=...)
Expand All @@ -28,13 +29,15 @@
PREVIEW_CHARS,
READS,
add_error_contract,
add_server_card,
add_skills,
listing_row,
)
from nimblebrain_server_sdk.errors import ErrorCode, ServiceError
from starlette.requests import Request
from starlette.responses import JSONResponse

from mcp_example import __version__
from mcp_example.api_client import ExampleAPIError, ExampleClient

# Logging setup - all logs to stderr (stdout is reserved for JSON-RPC). Diagnostics go
Expand All @@ -55,9 +58,15 @@

MAX_LIMIT = 100

# Create MCP server
# The Server Card's title and description, restated in server.json (a test holds them equal).
TITLE = "Example"
DESCRIPTION = "List and read items from the Example API."

# The name is reverse-DNS (the Server Card and the MCP Registry require it), and the version
# is the package's own: without `version=`, FastMCP reports its own version as the server's.
mcp = FastMCP(
"Example",
"com.example/example",
version=__version__,
instructions=(
"Before using tools, read the skill://example/SKILL.md resource "
"for tool selection guidance and workflow patterns."
Expand All @@ -66,6 +75,9 @@
# A ServiceError a tool raises reaches the caller as an error result with its code.
add_error_contract(mcp)
add_skills(mcp, [SKILLS_DIR / "example"])
# What a host reads, at <mcp-url>/server-card, before it connects. A connector has no
# placements; an app's server passes `placements=[...]` for its ui:// views.
add_server_card(mcp, title=TITLE, description=DESCRIPTION)

# Global client instance (lazy initialization)
_client: ExampleClient | None = None
Expand Down
Loading
Loading