Production-Grade MCP Server in TypeScript

作者:promptpacks发布日期:2026-09-21观看:28

面向企业内网的 TypeScript 版 MCP 服务器工程模板,同时支持 stdio 与 Streamable HTTP 双传输,用于把内部系统安全、可审计地开放给 AI 编程助手。

01/ 01

You are a principal distributed-systems engineer. Build a production MCP (2025-06-18 specification) server in TypeScript that exposes [INSERT INTERNAL SYSTEM, e.g. order-management API] to AI coding agents. Target users are [INSERT TEAM/PERSONA]; the server must support stdio for local IDEs and Streamable HTTP for remote agents, with resumable sessions. Work in strictly ordered modules; output one module at a time and wait for my written approval before proceeding. Module 1 Architecture: mermaid component and sequence diagrams, request lifecycle, capability negotiation, auth boundaries, and a security/availability risk register. Module 2 Scaffold: Node 22 ESM, TypeScript strict mode, Zod schemas, pino structured logs, env-plus-file config, and a distroless multi-stage Dockerfile running non-root. Module 3 Tools: implement a read-only query tool, a cursor-paginated list tool, and a state-changing tool requiring confirmation, each annotated with title, readOnlyHint, destructiveHint and idempotentHint. Module 4 Resources and prompts: parameterized resource templates with subscribe/change notifications plus at least two reusable prompts with validated arguments. Module 5 Data model: canonical entities for the domain, cache keys and ETags, cursor encoding, and invalidation rules when upstream data changes. Module 6 Resilience: JSON-RPC error mapping, per-call timeouts, backoff with jitter, per-upstream circuit breaker, and AbortSignal-based cancellation. Module 7 Security: OAuth 2.1 protected HTTP transport, per-tool scope checks, PII redaction, runtime secret injection, and append-only audit logs. Module 8 Testing: Vitest unit tests, stdio and HTTP integration tests, JSON-schema snapshots, fuzz tests for tool inputs, and an MCP spec-compliance matrix. Module 9 Observability: OpenTelemetry spans across tools and upstreams, token/usage metrics, error-rate dashboards, and alert thresholds. Module 10 Deployment: Kubernetes Deployment/Service/HPA manifests, graceful shutdown, health probes, rollout strategy, and a one-page incident runbook. Provide a README with quickstart commands, HTTP-transport curl examples, and an inspector-based local debugging guide. All code must compile under strict TypeScript with no `any` in public signatures; include CI commands for typecheck, lint, test and image build. State assumptions explicitly and list five clarifying questions about compliance constraints in [INSERT REGULATORY CONTEXT] before writing Module 2. ================

自动翻译

自动翻译中…

🔥热搜词

评论0

登录后参与评论

还没有评论,来抢沙发吧