Thank you for your interest in contributing to the MCP Swift SDK! This document provides guidelines and instructions for contributing.
If you work with an AI coding agent, also point it at AGENTS.md. That file covers the technical conventions in this codebase: message definitions, concurrency, platform gates, and test patterns.
The MCP community allows the use of AI assistant tooling for contributions. Before using AI agents, please review the MCP AI Policy to understand the guidelines and responsibilities for such contributions. In short:
- Disclose it. State in the PR description or issue that AI was used, and to what extent.
- Own it. You must understand the change and be able to explain it in your own words. When a maintainer asks a question, the answer should come from you, not be pasted from a chat window.
- Keep a human in the loop. Don't let agents open PRs, file issues, or post comments without a person reviewing the output first.
Open an issue and agree on the approach before writing code for:
- New public APIs, or changes to existing public API shapes
- Architectural changes, such as the
Transportprotocol or theClient/Serveractors - Changes that cut across many files or modules
- Behavior not covered by the MCP specification. These need a Specification Enhancement Proposal (SEP) first.
- Swift (6.1 or later)
- Node.js (22 or later), only needed for the MCP conformance tests
You can build the project as follows:
swift buildUse these commands to run tests:
swift test # All tests
swift test --filter CompletionTests # One suite
swift package generate-documentation --target MCP --warnings-as-errors # If you changed doc comments
scripts/run-conformance.sh # If you changed protocol behavior or transports- Write the subject in the imperative mood and sentence case, describing the behavior change, for
example
Decode any percent-encoded byte in non-base64 data URLs. A Conventional Commits prefix (fix:,test:,docs:,refactor:,chore:) is recommended. - Explain why in the body: the root cause, the relevant spec or RFC section, and how the change addresses it.
- Link the issue the PR addresses (
Fixes #123). - Disclose AI assistance (see AI Policy).
Follow the Swift API Design Guidelines, and match the style of the surrounding code. AGENTS.md has more rules and examples for message definitions, concurrency, platform gates, and tests.
- Formatting: use 4-space indentation.
.vscode/settings.jsonenables format-on-save, so don't commit unrelated formatting changes. Check your diff for reformatted lines outside your change. - Imports: match the file you're editing. Some files import specific Foundation symbols
(
import struct Foundation.Data), and others useimport Foundation. Listimport Loggingfirst. - No file headers: source files start with imports, with no license or copyright banner.
- Doc comments: document every
publicsymbol with///, a one-line summary, and DocC callouts (- Parameters:,- Returns:,- Throws:,- SeeAlso:,- Important:). Use``Symbol``links only for symbols that resolve, because CI fails on broken links. Use single backticks for method names, header names, and other literals. Code samples in doc comments are not compiled, so check them against the real API. - Organization: separate a type from its extensions with
// MARK: -, and label sections with// MARK: - Name. Put protocol conformances in separate extensions where the file already does. - Codable: use
private enum CodingKeys: String, CodingKey. Encode optional fields withencodeIfPresent. - Errors: throw
MCPErrorfrom protocol and transport code:.invalidParamsfor bad input,.methodNotFoundfor unsupported capabilities,.invalidRequestfor lifecycle violations, and.internalErrorotherwise, with a short message. OAuth failures useOAuthAuthorizationError. Don't swallow errors silently. If an error is intentionally ignored, log it and explain why. - Logging: use the transport's swift-log
Logger. Labels followmcp.transport.<kind>, and the default logger is a no-op. Usetracefor per-message events,debugfor lifecycle events,warningfor unexpected input, anderrorfor failures. Put structured values inmetadata:. Never log tokens, secrets, or authorization headers. - Security-sensitive code (
Authorization/,HTTPRequestValidation.swift): validate URLs and inputs with the existing validators. Keep secrets out of errors and logs, and add tests for each rejected input.
Report vulnerabilities privately through GitHub Security Advisories, as described in SECURITY.md. Don't report them in public issues, discussions, or pull requests.
By contributing, you agree that new contributions are licensed under Apache 2.0. Existing code remains under MIT. See LICENSE.