Markdown Editor

MCP Server Specification Template (Model Context Protocol)

Specify an MCP server (spec revision 2026-07-28): transport, tools, resources, prompts, OAuth, security, testing

ШІ та даніСтандартModel Context Protocol specification, revision 2026-07-28mcpserverspec

Як використовувати: Use it when exposing a system to AI applications over the Model Context Protocol. Confirm the target protocol revision and transport first, then define each tool with schema, annotations and side effects. The main pitfall is treating tool annotations as a security control and skipping input validation and audience-bound tokens.

Перегляд

MCP Server Specification: [Server name]

Specification for a Model Context Protocol (MCP) server: what it exposes to AI applications (tools, resources, prompts), over which transport, with which authorization, and how it is secured, tested and versioned. Written against MCP specification revision 2026-07-28 (the latest revision on modelcontextprotocol.io when this template was written; previous revision 2025-11-25). Check the current revision before you start. Replace every [bracketed] value and every row marked Example.

FieldValue
Document ID[MCP-SPEC-001]
Server name and version[example-billing-mcp] [1.0.0]
Target MCP revision[2026-07-28]; backward compatible with [2025-11-25 / none]
Status[Draft / In review / Approved]
Owner[@owner]
Reviewers[@security-reviewer], [@platform-engineer]
Repository[URL]
Last updatedYYYY-MM-DD

1. Purpose and context

[Describe the system the server wraps and who will connect to it.] Example: Exposes read access to invoices and a limited credit operation from the billing service, for use by the internal support assistant and by engineers in their IDE assistants. It does not expose payment card data, refunds or account deletion.

ItemValue
Wrapped systemExample: Billing API v4
Intended hostsExample: Support assistant (remote), IDE assistants (local)
UsersExample: Support staff and billing engineers
Data classificationExample: Confidential (customer billing data)

2. Transport and protocol

AspectChoice
Transport[stdio / Streamable HTTP / both]
Endpoint (HTTP)[https://mcp.example.com/mcp] single MCP endpoint accepting POST
Response modes[JSON object / request-scoped SSE stream] per request
Discoveryserver/discover returns supported versions, capabilities and server identity
Change notifications[subscriptions/listen for list changes / not used]
Older clients[Fallback to initialize-based revisions: yes or no]

Transport requirements to verify:

  • stdio: newline-delimited JSON-RPC on stdin and stdout; logs go to stderr only; credentials come from the environment, not from MCP authorization.
  • Streamable HTTP: validate the Origin header on every request and answer 403 when it is present and invalid (DNS rebinding protection); bind to 127.0.0.1 when running locally; require the MCP-Protocol-Version, Mcp-Method and (for tools/call, resources/read, prompts/get) Mcp-Name headers and reject header-body mismatches with 400.
  • Statelessness: no per-connection state. Where a tool needs state across calls, return an explicit opaque handle and accept it as an argument, checking authorization on every call.

3. Capabilities

CapabilityDeclaredNotes
tools[Yes]listChanged: [true / false]
resources[Yes / No]Subscriptions to updates: [yes / no]
prompts[Yes / No]listChanged: [true / false]
completions[Yes / No]Argument completion for prompts and resource templates
Extensions[None / list]Example: Tasks extension for long-running exports
Deprecated featuresNot usedRoots, Sampling and Logging are deprecated in 2026-07-28; avoid in new servers

4. Tools

NameTitleSide effectsreadOnlyHintdestructiveHintidempotentHintopenWorldHint
get_invoiceExample: Get invoiceNonetruen/an/afalse
search_invoicesExample: Search invoicesNonetruen/an/afalse
apply_creditExample: Apply account creditWrites a ledger entryfalsefalsefalsefalse

Defaults in the schema, if a hint is omitted: readOnlyHint false, destructiveHint true, idempotentHint false, openWorldHint true. Set every hint explicitly so clients do not assume the worst or the best.

4.1 Tool definition: apply_credit

{
  "name": "apply_credit",
  "title": "Apply account credit",
  "description": "Add a credit in USD to a customer account. Use only after confirming the charge is a duplicate or caused by an outage. Maximum 50 USD. Creates a ledger entry that finance can reverse within 30 days.",
  "inputSchema": {
    "type": "object",
    "properties": {
      "account_id": {"type": "string", "pattern": "^acc_[a-z0-9]{12}$"},
      "amount_usd": {"type": "number", "minimum": 0.01, "maximum": 50},
      "reason_code": {"type": "string", "enum": ["DUPLICATE_CHARGE", "SERVICE_OUTAGE"]}
    },
    "required": ["account_id", "amount_usd", "reason_code"],
    "additionalProperties": false
  },
  "outputSchema": {
    "type": "object",
    "properties": {"credit_id": {"type": "string"}, "balance_usd": {"type": "number"}},
    "required": ["credit_id", "balance_usd"]
  },
  "annotations": {"readOnlyHint": false, "destructiveHint": false, "idempotentHint": false, "openWorldHint": false}
}

Results with an outputSchema return structuredContent that conforms to it, plus the same JSON serialised in a text content block for older clients.

5. Resources and prompts

5.1 Resources

URI or templateNameMIME typeDescriptionCache hint
billing://policy/creditsExample: Credit policytext/markdownCurrent credit rulesttlMs 3,600,000, public
billing://invoices/{invoice_id}Example: Invoiceapplication/jsonOne invoicettlMs 60,000, private

List and read results carry ttlMs and cacheScope; use private for anything user-specific.

5.2 Prompts

NameArgumentsPurpose
explain_invoiceExample: invoice_id (required), language (optional)Produces a customer-friendly explanation of each line item

6. Authorization

AspectDesign
ModelMCP server acts as an OAuth 2.1 resource server
Protected Resource MetadataExample: https://mcp.example.com/.well-known/oauth-protected-resource (RFC 9728) listing the authorization server
Authorization serverExample: Corporate identity provider with RFC 8414 or OpenID Connect discovery
Client registrationClient ID Metadata Documents preferred; pre-registration for internal hosts; Dynamic Client Registration only for compatibility (deprecated)
Token validationAudience must be this server's canonical URI (RFC 8707 resource indicator); reject other tokens; no token passthrough to the billing API
ScopesExample: invoices:read, credits:write; 401 and 403 responses carry the required scope in WWW-Authenticate
Tool visibilityExample: tools/list returns apply_credit only to tokens with credits:write
Downstream callsExample: Server uses its own service credentials with per-user audit fields

7. Security considerations

IDConcernControlTest
MS-01User consent before state changesWrite tools marked readOnlyHint: false; hosts are expected to confirm with the user; server enforces limits regardlessManual host test
MS-02Least privilegeSeparate scopes for read and write; service account limited to credit endpointScope test matrix
MS-03Input validationJSON Schema validation plus business checks (account ownership, daily cap)Unit and fuzz tests
MS-04Untrusted content in resultsInvoice memo fields marked as data; no instructions in tool descriptions that depend on returned textInjection test set
MS-05Rate limitingExample: 30 tools/call per minute per userLoad test
MS-06Output sanitisationCard numbers masked; no secrets in results or errorsSnapshot tests
MS-07DNS rebinding (HTTP)Origin validation; localhost binding for local modeIntegration test
MS-08Sensitive headersNo secrets or personal data in x-mcp-header parametersCode review

8. Error handling

SituationResponse
Unknown tool, malformed requestJSON-RPC error (for example -32602 Invalid params)
Validation or business rule failureTool result with isError: true and an actionable message, for example "amount_usd must be 50 or less"
Backend unavailableTool result with isError: true, "billing service unavailable, retry later"
Unsupported protocol version400 with UnsupportedProtocolVersionError listing supported versions
Expired or unknown handleisError: true explaining that a new handle is needed

9. Logging and observability

[Example: Structured logs to stderr (stdio) or the platform log pipeline (HTTP) with request ID, method, tool name, user ID, latency and outcome. Arguments are logged with account IDs hashed. Trace context propagated through _meta (traceparent) into OpenTelemetry. Audit log of every apply_credit call kept for [7] years.]

10. Versioning and compatibility

  • Server version follows semantic versioning; a breaking change to any tool's input schema or behaviour is a major version.
  • Tools are added rather than changed; deprecated tools keep working for [90] days and say so in their description.
  • Supported MCP revisions: [2026-07-28]; [2025-11-25 via fallback].
  • listChanged notifications are sent when the tool set changes at runtime.

11. Testing

TestToolPass criteria
Interactive checkMCP Inspector (npx @modelcontextprotocol/inspector)All tools, resources and prompts listed and callable with valid inputs
Schema conformanceContract tests against the published schemaAll results validate; structuredContent matches outputSchema
AuthorizationIntegration tests with tokens of each scope401/403 as designed; no cross-tenant access
InjectionAdversarial fixtures in invoice memosNo change in tool behaviour
Host compatibility[List of hosts]Tools usable end to end

Standard and licence note

Based on the Model Context Protocol specification, revision 2026-07-28, published at modelcontextprotocol.io; structure and requirement names summarised in original wording. Check the specification for the current revision and normative text. Template licence: MIT.

Схожі шаблони