/dogsled-core:build-mcp-serverfrom dogsled-core
Guides building a remote MCP server from scratch: choose language/SDK, define tools, implement streamable HTTP transport, add auth, deploy publicly, and connect as a custom MCP source.
Ships in dogsled-core. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Use this skill when exposing Dogsled capabilities through an MCP server.
Load the full reference only when the task needs its schemas, command tables, examples, or troubleshooting detail:
Use this when a user wants to expose their own data or operations as a
remote MCP server so the host agent (or any MCP client) can pull
data from it. The endgame: a publicly reachable HTTPS URL implementing
the streamable-HTTP MCP transport, which you then wire up via
add-custom-mcp-integration as a Dogsled custom_mcp source.
This skill is not about consuming MCP — for that, run
add-custom-mcp-integration (or mcp-discover to scaffold from an
existing server's tools).
A long-running HTTPS service that:
tools/list,
tools/call).bearer or api-key for the
simplest production-ready shape — Dogsled's custom_mcp reads both).The protocol spec is at https://spec.modelcontextprotocol.io/. The
authoritative SDKs are
@modelcontextprotocol/sdk
(TypeScript) and
mcp (Python).
Verify the current API shape against each SDK's README before
copy-pasting — the SDKs are pre-1.0 and add/rename helpers between
minor versions.
AbsoluteHttpsUrlSchema callers and DNS pre-resolution.mkdir my-mcp-server && cd my-mcp-server
npm init -y
npm install @modelcontextprotocol/sdk zod
npm install --save-dev typescript tsx @types/node
npx tsc --init
Minimum tsconfig.json adjustments: "module": "NodeNext",
"target": "ES2022", "moduleResolution": "NodeNext".
mkdir my-mcp-server && cd my-mcp-server
uv init
uv add "mcp[cli]"
The Python SDK uses Pydantic models and supports both stdio (for desktop Claude) and streamable HTTP (for hosted access — that's what you want for Dogsled).
A tool is a typed function the MCP client can invoke. Give it a clear name, a JSON Schema for arguments, and a handler that returns serializable JSON.
// src/server.ts
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { z } from 'zod';
const server = new McpServer({
name: 'my-team-tools',
version: '0.1.0',
});
server.tool(
'list_projects',
'List projects in the team',
{
team_id: z.string().describe('UUID of the team'),
limit: z.number().int().min(1).max(100).default(50),
},
async ({ team_id, limit }) => {
const rows = await db.query(
'select id, name, status, created_at from projects where team_id = $1 limit $2',
[team_id, limit]
);
// Streamable HTTP returns "content" parts; the conventional shape
// for data tools is a single text part holding JSON.
return {
content: [
{
type: 'text',
text: JSON.stringify({ projects: rows }),
},
],
};
}
);
server.tool(
'get_project',
'Get a single project by id',
{ project_id: z.string() },
async ({ project_id }) => {
const row = await db.query('select * from projects where id = $1', [project_id]);
if (!row) {
return {
content: [{ type: 'text', text: JSON.stringify({ error: 'not_found' }) }],
isError: true,
};
}
return {
content: [{ type: 'text', text: JSON.stringify({ project: row }) }],
};
}
);
export { server };
# server.py
from mcp.server import FastMCP
from pydantic import Field
mcp = FastMCP("my-team-tools")
@mcp.tool()
def list_projects(
team_id: str = Field(description="UUID of the team"),
limit: int = Field(default=50, ge=1, le=100),
) -> dict:
"""List projects in the team."""
rows = db.query(
"select id, name, status, created_at from projects where team_id = %s limit %s",
(team_id, limit),
)
return {"projects": rows}
@mcp.tool()
def get_project(project_id: str) -> dict:
"""Get a single project by id."""
row = db.query("select * from projects where id = %s", (project_id,))
if not row:
return {"error": "not_found"}
return {"project": row}
The @mcp.tool() decorator infers the JSON Schema from the function
signature. Pydantic Field(description=...) becomes the schema's
description.
Streamable HTTP combines:
/mcp — JSON-RPC request body, used for initialization
(initialize), tool listing (tools/list), and tool calls
(tools/call)./mcp — SSE stream the server uses to push notifications and
long-running tool results.Auth lives in HTTP headers (Authorization: Bearer ... or a custom
x-api-key). Cookies are also supported but headers are simpler.
// src/index.ts
import express from 'express';
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
import { server } from './server.js';
const app = express();
app.use(express.json({ limit: '4mb' }));
// Bearer-token middleware (see Step 4).
app.use('/mcp', requireBearer(process.env.MCP_AUTH_TOKEN!));
const transport = new StreamableHTTPServerTransport({
sessionIdGenerator: () => crypto.randomUUID(),
});
await server.connect(transport);
// Handle both POST (request) and GET (SSE stream) on /mcp.
app.all('/mcp', async (req, res) => {
await transport.handleRequest(req, res, req.body);
});
const port = Number(process.env.PORT ?? 8080);
app.listen(port, () => {
console.log(`MCP server listening on :${port}/mcp`);
});
# main.py
import os
from server import mcp
# FastMCP exposes streamable_http_app() which returns a Starlette app.
app = mcp.streamable_http_app()
# Mount auth middleware around it (see Step 4).
from middleware import RequireBearerMiddleware
app.add_middleware(RequireBearerMiddleware, token=os.environ["MCP_AUTH_TOKEN"])
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=int(os.environ.get("PORT", "8080")))
Dogsled's custom_mcp reads three auth shapes off
McpTransportAuthSchema: none, bearer, api-key. Implement
whichever fits your security model. Always compare tokens with a
constant-time function and never log the raw token.
import { Request, Response, NextFunction } from 'express';
import { timingSafeEqual } from 'node:crypto';
export function requireBearer(expected: string) {
const expectedBuf = Buffer.from(expected, 'utf-8');
return (req: Request, res: Response, next: NextFunction) => {
const header = req.header('authorization') ?? '';
const match = /^Bearer\s+(.+)$/.exec(header);
if (!match) {
res.status(401).json({ error: 'missing_bearer' });
return;
}
const presented = Buffer.from(match[1], 'utf-8');
if (presented.length !== expectedBuf.length || !timingSafeEqual(presented, expectedBuf)) {
res.status(401).json({ error: 'invalid_token' });
return;
}
next();
};
}
const HEADER = 'x-api-key';
const keys = (process.env.MCP_API_KEYS ?? '').split(',').filter(Boolean);
app.use('/mcp', (req, res, next) => {
const presented = req.header(HEADER);
if (!presented) return res.status(401).json({ error: 'missing_api_key' });
// Constant-time compare across the allowed key set.
const presentedBuf = Buffer.from(presented, 'utf-8');
const ok = keys.some((k) => {
const kBuf = Buffer.from(k, 'utf-8');
return kBuf.length === presentedBuf.length && timingSafeEqual(kBuf, presentedBuf);
});
if (!ok) return res.status(401).json({ error: 'invalid_api_key' });
next();
});
import hmac
from starlette.middleware.base import BaseHTTPMiddleware
from starlette.responses import JSONResponse
class RequireBearerMiddleware(BaseHTTPMiddleware):
def __init__(self, app, token: str):
super().__init__(app)
self.token = token.encode("utf-8")
async def dispatch(self, request, call_next):
if not request.url.path.startswith("/mcp"):
return await call_next(request)
header = request.headers.get("authorization", "")
prefix = "Bearer "
if not header.startswith(prefix):
return JSONResponse({"error": "missing_bearer"}, status_code=401)
presented = header[len(prefix):].encode("utf-8")
if not hmac.compare_digest(presented, self.token):
return JSONResponse({"error": "invalid_token"}, status_code=401)
return await call_next(request)
type: bearer — simplest, single shared secret, rotate by
redeploying. Best for an internal server consumed by a small number
of clients.type: api-key — per-client keys (the keys slice above), so
you can revoke one client without rotating all of them. Best for
multi-tenant servers or when you want to attribute calls.type: none — only for truly public read-only data. Dogsled
accepts it but the SSRF + rate-limit on the extractor side is your
only defense.token_url, client_id, client_secret, scopes). The MCP SDK
side requires you to validate the JWT yourself. Out of scope for
this skill — use it when you have an existing OIDC IdP and need
per-token scoping.Set MCP_AUTH_TOKEN to the same temporary local test token in both terminals, then run the server locally:
# TypeScript
npx tsx src/index.ts
# Python
uv run python main.py
In a second terminal, probe with curl:
# Initialize the session — capture the Mcp-Session-Id from the response.
curl -i -X POST http://localhost:8080/mcp \
-H "Authorization: Bearer $MCP_AUTH_TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2025-03-26",
"capabilities": {},
"clientInfo": {"name": "curl", "version": "0.0.1"}
}
}'
# Then list tools (replace <SID> with the value of Mcp-Session-Id from above).
curl -X POST http://localhost:8080/mcp \
-H "Authorization: Bearer $MCP_AUTH_TOKEN" \
-H "Mcp-Session-Id: <SID>" \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","id":2,"method":"tools/list"}'
Or use the MCP Inspector for a richer UI:
npx @modelcontextprotocol/inspector http://localhost:8080/mcp
Once the inspector connects and lists your tools, you have a working
MCP server. Point Dogsled's mcp-discover skill at the same URL to
auto-scaffold the resource YAML, then refine it with
add-custom-mcp-integration.
Three concrete recipes. Pick the platform that matches your team's ops posture.
# Dockerfile
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY . .
RUN npm run build
EXPOSE 8080
CMD ["node", "dist/index.js"]
# Build and deploy in one shot. --timeout=3600 lets streamable HTTP
# hold the SSE stream open for up to an hour per request.
gcloud run deploy my-mcp-server \
--source . \
--region us-central1 \
--allow-unauthenticated \
--timeout=3600 \
--set-secrets MCP_AUTH_TOKEN=mcp-auth-token:latest \
--memory 512Mi
Cloud Run will return an HTTPS URL like
https://my-mcp-server-<hash>-uc.a.run.app. Use https://<that>/mcp
as the url in your Dogsled custom_mcp source.
# fly.toml
app = "my-mcp-server"
primary_region = "iad"
[build]
builder = "paketobuildpacks/builder:base"
[env]
PORT = "8080"
[http_service]
internal_port = 8080
force_https = true
auto_stop_machines = false # streamable HTTP needs a long-lived process
auto_start_machines = true
min_machines_running = 1
[http_service.checks]
grace_period = "10s"
interval = "30s"
method = "GET"
path = "/mcp"
protocol = "http"
timeout = "5s"
fly launch --no-deploy # accept defaults, edit fly.toml as above
fly secrets set MCP_AUTH_TOKEN=...
fly deploy
Vercel works only for short tool calls — Pro plans cap function duration at ~30 minutes (and Hobby at 10 seconds). If your tools return quickly and don't stream incremental progress for hours, it's viable; otherwise pick Cloud Run or Fly.
// vercel.json
{
"functions": {
"api/mcp.ts": {
"maxDuration": 300,
},
},
}
Use api/mcp.ts to handle both POST and GET; the StreamableHTTPServerTransport
fits in a Node serverless function as long as you allocate enough
maxDuration.
Once your server is at a stable HTTPS URL, hand off to
add-custom-mcp-integration:
transports[0].url in the Dogsled
source.yml.${{ env.<VAR> }} in
transports[0].auth, declared in auth_env_vars.resources/<tool>.yml with the tool: block.dogsled extract validate <source> → verify → run.# Your Dogsled source.yml after deploy:
spec_version: '2'
type: source
source_type: custom_mcp
dogsled_source_kind: custom_mcp
name: my_team_tools
auth_env_vars:
- MY_TEAM_MCP_TOKEN
transports:
- id: default
type: mcp_http
url: https://my-mcp-server-<hash>-uc.a.run.app/mcp
auth:
type: bearer
token: ${{ env.MY_TEAM_MCP_TOKEN }}
default_transport: default
Before exposing the server publicly:
AbsoluteHttpsUrlSchema enforces it on the connection too.timingSafeEqual /
hmac.compare_digest. Never === / == on secret tokens.express.json({ limit: '4mb' }), Starlette via middleware).LIMIT, page
counts, file sizes per call.When authoring this skill's worked examples, fetch the current SDK
API shape with the context7 MCP server (query-docs tool) — the SDKs
add and rename helpers between minor versions, and stale syntax is the
top failure mode.
add-custom-mcp-integration — connect your deployed MCP server as a
Dogsled custom_mcp source (the natural next step).mcp-discover — auto-scaffold Dogsled resource YAML from your
server's tools/list output.What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub bobsled-inc/dogsled-core --plugin dogsled-core65 skills in this plugin
/add-custom-api-integrationAuthor a generic custom_api source for any REST/GraphQL API purely in YAML — inline transport (base_url + auth), one declarative resource per endpoint, then validate/verify/extract. Use when the API isn't in the bundled catalog./add-custom-mcp-integrationAuthor a custom_mcp source for any remote MCP server (Model Context Protocol over streamable HTTP) purely in YAML — inline mcp_http transport (url + auth + auth_env_vars), one resource_kind mcp resource per tool, then validate/verify/extract. Use when the MCP server isn't in the bundled catalog./add-database-destinationAdd a new database load destination (e.g., Snowflake, PostgreSQL, ClickHouse) to the @bobsled-inc/loader package. Implements the DatabaseDestination interface with full append/merge/full_refresh support./add-file-destinationAdd a new file-based load destination (e.g., Azure Blob Storage, R2, MinIO) to the @bobsled-inc/loader package. Walks through class implementation, config schema, factory wiring, CLI options, check command, and tests./add-file-storage-sourceOnboard documents (PDF, DOCX, PPTX, HTML, Markdown, text, email) from an Amazon S3 or Google Cloud Storage bucket — author a file-storage integration (source_type s3|gcs, bucket + auth) plus a document resource that parses and token-chunks each file, and an optional pipeline that embeds the chunks. Use when the user wants to ingest files/documents from cloud object storage rather than from an API./add-integrationAdd a new API integration to the @bobsled-inc/integrations library. Automates OpenAPI spec discovery, YAML generation, curation, and validation.