custom-mcp-server
Production MCP server for data annotation workflows, exposing six tools backed by AWS S3, DynamoDB, and Slack with JWT auth, rate limiting, and exponential-backoff retries.
README
custom-mcp-server
A production Model Context Protocol server for a data-annotation workflow. It exposes six tools over the MCP stdio transport, backed by AWS S3 + DynamoDB and Slack, with JWT auth, per-tool rate limiting, and exponential-backoff retries.
Prerequisites
- Node.js 20 LTS
- npm
- AWS account (S3 bucket + DynamoDB table) and a Slack bot token for runtime use (not required to run the test suite — all external calls are mocked)
Install
npm install
Environment setup
Copy .env.example to .env and fill in the values. Keys:
| Key | Required by | Notes |
|---|---|---|
AWS_REGION |
all AWS tools | e.g. us-east-1 |
AWS_ACCESS_KEY_ID |
all AWS tools | secret — keep out of source control |
AWS_SECRET_ACCESS_KEY |
all AWS tools | secret |
S3_BUCKET_NAME |
s3_upload, s3_download |
default bucket |
DYNAMO_TABLE_NAME |
dynamo_read/write, annotation_status |
table with partition key id |
SLACK_BOT_TOKEN |
slack_notify, annotation_status |
secret, xoxb-... |
SLACK_DEFAULT_CHANNEL |
slack_notify, annotation_status |
e.g. #annotations |
OAUTH_ISSUER |
auth (every call) | expected iss claim |
OAUTH_AUDIENCE |
auth (every call) | expected aud claim |
JWKS_URI |
auth (RS256) | JWKS endpoint for signature verification |
JWT_SECRET |
auth (HS256, dev only) | optional; ≥ 32 chars; refused when NODE_ENV=production |
NODE_ENV |
auth | set to production to force RS256/JWKS and forbid HS256 |
RATE_LIMIT_PER_MIN |
rate limiter | default 100 |
RETRY_MAX_ATTEMPTS |
retry | default 3 |
RETRY_BASE_DELAY_MS |
retry | default 200 |
LOG_LEVEL |
logger | debug/info/warn/error, default info |
Build / test / run
npm run build # compile TypeScript to dist/
npm run typecheck # tsc --noEmit
npm test # Jest (ESM) — all external calls mocked
npm start # node dist/server.js (stdio transport)
Tools
| Tool | Input (required**) | Required scope | Behavior |
|---|---|---|---|
s3_upload |
key, contentBase64, contentType? |
s3:write |
Upload base64 content to S3 under the caller's prefix; returns { bucket, key, etag } |
s3_download |
key** |
s3:read |
Download object from the caller's prefix; returns { bucket, key, contentBase64, contentType } |
dynamo_read |
id**, consistentRead? |
dynamo:read |
Read a record the caller owns; returns the item (without owner) or { found: false } |
dynamo_write |
id, attributes, overwrite? |
dynamo:write |
Put a record stamped with the caller as owner; can only overwrite records the caller owns |
slack_notify |
message**, channel?, threadTs? |
slack:write |
Post to Slack (text sanitized); returns { channel, ts } |
annotation_status |
taskId**, newStatus?, notify? |
annotation:read (+ annotation:write to update) |
Read/update a task the caller owns, optionally notify Slack |
Auth model
Every tool call is authenticated and authorized:
- Authentication. The caller supplies a JWT via
_meta.authorization(optionallyBearer-prefixed). The expected algorithm is pinned from server configuration — not the token header — to block algorithm-confusion attacks: RS256 (verified againstJWKS_URI) by default, or HS256 only when aJWT_SECRET(≥ 32 chars) is set andNODE_ENVis notproduction. The server checksiss/aud/expiry (with a small clock skew) and derives anAuthContext(subject,scopes). Invalid tokens →AUTH_INVALID. - Scope authorization. Each tool declares
requiredScopes. A token missing a required scope is rejected withFORBIDDENbefore the handler runs. - Object-level authorization (ownership). DynamoDB records carry an
ownerattribute and S3 keys are confined to a per-subject prefix (<subject>/…). Callers can only read/update their own records and objects; foreign records are reported as not-found to avoid ID enumeration. This prevents IDOR. - Error handling. Callers receive only a stable error
codeplus arequestId; full error detail is logged server-side (stderr) and never leaked to the client.
JWKS keys are fetched through a cached, rate-limited client to avoid a network round-trip (and IdP DoS) on every verification. S3 up/downloads are capped at 10 MiB to bound memory use.
Rate limiting & retries
- Rate limit: 100 requests/min per principal+tool (configurable), in-memory
per process, keyed by
subject:toolso one caller cannot starve others. Unknown tool names are rejected before consuming limiter budget. Exceeding it yieldsRATE_LIMITED. - Retry: transient failures (
retryable: true) are retried up to 3 times with exponential backoff (baseDelay * 2^(n-1)). Conflicts, validation, and auth errors are never retried. - Idempotency note: retries wrap non-idempotent writes (
dynamo_write,slack_notify). Only transient errors are retried, but adding idempotency keys is recommended future work.
Cursor setup
.cursor/mcp.json registers the server with Cursor:
{
"mcpServers": {
"custom-mcp-server": {
"command": "node",
"args": ["dist/server.js"],
"env": { "AWS_REGION": "us-east-1", "...": "..." }
}
}
}
Secrets (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, SLACK_BOT_TOKEN,
JWT_SECRET) are not placed in mcp.json; provide them via your shell
environment / .env. Run npm run build before launching so dist/server.js
exists.
Architecture
See PLAN.md for the full milestone plan, interface contracts, and
blocker analysis. Source layout:
src/
server.ts stdio transport + tool-call pipeline
config.ts env loading + validation (zod)
types.ts shared interface contracts
errors.ts AppError exception + guards
security.ts scopes, ownership, key-scoping & sanitization helpers
logger.ts stderr-only structured logger
auth/oauth.ts JWT validation (algorithm-pinned) + cached JWKS
middleware/ retry.ts, rate-limiter.ts
clients/ s3/dynamo/slack factories
tools/ one file per tool + index.ts
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。