mcp-server
Skill1 starsChanged 8 months agoMITView on GitHub
MCP server design, development, and audit using the Python SDK (FastMCP). Use when: creating a new MCP server, wrapping an API as MCP tools, auditing an existing MCP server for patterns and gaps, adding auth/secrets/retry/observability to an MCP server, choosing between tools vs resources vs prompts, designing MCP resources or resource templates, creating MCP prompts for workflow bootstrapping, choosing between low-level Server and FastMCP, designing tool contracts, configuring pydantic-settings, adding structured logging, writing MCP server tests, or improving an existing MCP server codebase.
- Reads credentials
8 other projects use a version of this.
Adopted by
Most recently taken up by
- timsonner/agent-skillstheir own version, first seen Aug 30, 2026
- saschb2b/skillstheir own version, first seen Aug 8, 2026
- rrezartprebreza/spring-boot-skillstheir own version, first seen Aug 7, 2026
- Happy-Technologies-LLC/happy-platform-skillstheir own version, first seen Jul 28, 2026
- nimadorostkar/Claude-Skills-collectiontheir own version, first seen Jul 14, 2026
- ivanshamaev/de-agent-skillstheir own version, first seen May 17, 2026
Other versions8 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 8
- rrezartprebreza/spring-boot-skills★ 293same name
- Happy-Technologies-LLC/happy-platform-skills★ 40same name
- nimadorostkar/Claude-Skills-collection★ 28same name
- ivanshamaev/de-agent-skills★ 21same name
- saschb2b/skills★ 19same name
- DaleStudy/skills★ 4same name
- prizmad/agent-skills★ 2same name
- timsonner/agent-skills★ 2same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository42 other files it gives its agents.
- accessibility-testingSkill
- alternatives-analysisSkill
- anomaly-detectionSkill
- api-designSkill
- async-messagingSkill
- caching-strategiesSkill
- chartsSkill
- cicdSkill
- code-reviewSkill
- commsSkill
- critical-feedbackSkill
- data-analysisSkill
- databaseSkill
- data-migrationsSkill
- data-visualizationSkill
- dependency-managementSkill
- dockerSkill
- error-handlingSkill
- feature-flagsSkill
- git-workflowSkill
- goalsSkill
- ide-setupSkill
- large-changeSkill
- logging-metricsSkill
- markdown-docsSkill
- meeting-agendasSkill
- okrsSkill
- presentationsSkill
- product-managementSkill
- prompt-writingSkill
- pythonSkill
- reclassificationSkill
- release-managementSkill
- retrospectivesSkill
- roadmap-planningSkill
- securitySkill
- stakeholder-commsSkill
- statisticsSkill
- status-updatesSkill
- testingSkill
- ticket-writingSkill
- typescriptSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
25 rules. 0 are common, 9 are distinctive, and 16 are very specific to this project.
0
Common
Most of the 7 edited versions we read keep these.
9
Distinctive
This author's own choices. Worth a look.
16
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 23
Use FastMCP from the official MCP Python SDK (mcp[cli]>=1.27.0).
- Very specific: line 25
Do not use the low-level mcp.server.Server class unless you need custom protocol handling (e.g., streaming, custom transport).
- Distinctive: line 76
Use src/ layout with hatchling build system.
- Very specific: line 77
Keep server.py focused on FastMCP instance, lifespan, and AppContext — not tool logic.
- Very specific: line 139
Use pydantic-settings BaseSettings with an env prefix unique to the server.
- Very specific: line 161
Rules: All fields must have sensible defaults.
- Very specific: line 176
Use asyncio.Lock for token refresh to prevent concurrent duplicate refreshes.
- Very specific: line 178
Never log tokens. Exclude from __repr__ with repr=False.
- Very specific: line 192
Use keyring for macOS Keychain.
- Very specific: line 193
Use boto3 for AWS Secrets Manager.
- Distinctive: line 194
Use env vars as fallback for CI/testing.
- Distinctive: line 196
Never log secret values. Log key names at debug level only.
- Distinctive: line 200
Use httpx (async) with retry, rate limiting, and structured logging.
- Distinctive: line 204
Use tenacity. Do not implement custom retry loops.
- Very specific: line 248
Use structlog with JSON output to stderr.
- Very specific: line 266
Every tool call must produce a structured audit log entry with: timestamp, event="tool_call", tool, user, request_id (uuid per call, sent …
- Distinctive: line 289
Every tool must have: one-sentence description, Args section (every param with type, default, constraints), return description.
- Distinctive: line 293
Use type hints for automatic validation via FastMCP.
- Distinctive: line 296
Use Pydantic models for complex dict inputs (create/update operations).
- Very specific: line 300
All tools return dict[str, Any].
- Very specific: line 317
Key rule: If the agent should independently decide to call it, use a tool.
- Very specific: line 321
URI design: Use a custom scheme per RFC 3986 (myapp://path/to/resource).
- Very specific: line 323
Every resource and template must have a name, description, and MIME type (text/markdown, application/json, etc.).
- Distinctive: line 346
Use prompts for user-initiated workflow starters — not as substitutes for tool docstrings.
- Very specific: line 354
Rules: Keep arguments minimal and optional where possible.
“Common” is measured: kept by at least 6 in 10 of the 7 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
MCP Server Standards
When to Use
- Creating a new MCP server (wrapping an API, database, or internal service)
- Auditing an existing MCP server for architecture, security, testing, or documentation gaps
- Adding resilience patterns (retry, rate limiting, circuit breaker) to an MCP server
- Adding authentication and secrets management
- Writing or improving MCP server tests
- Designing tool contracts (inputs, outputs, docstrings)
- Setting up configuration, logging, and observability
Framework
Use FastMCP from the official MCP Python SDK (mcp[cli]>=1.27.0). FastMCP provides decorator-based tool registration, automatic input validation from type hints, and built-in lifespan management.
Do not use the low-level mcp.server.Server class unless you need custom protocol handling (e.g., streaming, custom transport). FastMCP covers all standard use cases.
from mcp.server.fastmcp import FastMCP, Context
mcp = FastMCP("my-server", lifespan=app_lifespan)
@mcp.tool()
async def my_tool(
query: str,
limit: int = 25,
ctx: Context = None,
) -> dict[str, Any]:
"""One-sentence description of what this tool does.
Args:
query: What to search for.
limit: Maximum results to return (default 25, max 500).
"""
app = ctx.request_context.lifespan_context
return await app.client.request("GET", "/endpoint", params={"q": query, "limit": limit})Project Structure
my-mcp-server/
├── src/my_mcp_server/
│ ├── __main__.py # Entry point: mcp.run()
│ ├── server.py # FastMCP instance, lifespan, AppContext
│ ├── client.py # HTTP client with retry, rate limiting, logging
│ ├── auth.py # Pluggable auth via Protocol
│ ├── secrets.py # Keychain / AWS / env secret backends
│ ├── config.py # pydantic-settings BaseSettings
│ ├── observability.py # Structured logging, secret redaction
│ ├── metrics.py # Optional Prometheus instrumentation
│ └── tools/ # 1 file per domain when >10 tools or multiple domains
├── tests/
│ ├── conftest.py
│ ├── unit/ # test_server, test_client, test_auth, test_secrets, test_config
│ └── integration/ # @pytest.mark.integration, skipped by default
├── docs/ # DESIGN.md, ROADMAP.md, SECURITY.md, changes/
├── configs/mcp/ # MCP client config template
├── pyproject.toml
├── README.md
├── ONBOARDING.md
└── uv.lockRules
- Use src/ layout with hatchling build system.
- Keep
server.pyfocused on FastMCP instance, lifespan, and AppContext — not tool logic. - Each concern (auth, secrets, config, client, logging) gets its own module.
pyproject.toml
[project]
name = "my-mcp-server"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = [
"mcp[cli]>=1.27.0",
"httpx>=0.28",
"pydantic>=2.0",
"pydantic-settings>=2.0",
"structlog>=24.0",
"tenacity>=8.0",
"keyring>=25.0",
]
[dependency-groups]
dev = [
"pytest>=8.0", "pytest-asyncio>=0.24", "pytest-cov>=5.0",
"respx>=0.22", "ruff>=0.9", "mypy>=1.15",
"boto3>=1.34", "boto3-stubs[secretsmanager]>=1.34",
]
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project.scripts]
my-mcp-server = "my_mcp_server.__main__:main"
[tool.ruff]
line-length = 100
target-version = "py312"
[tool.ruff.lint]
select = ["E", "F", "I", "N", "UP", "B", "SIM"]
[tool.ruff.format]
quote-style = "double"
[tool.mypy]
strict = true
python_version = "3.12"
[tool.pytest.ini_options]
asyncio_mode = "auto"
testpaths = ["tests"]
markers = ["integration: requires valid API credentials"]
addopts = "-m 'not integration'"
[tool.coverage.report]
fail_under = 85
show_missing = true
exclude_also = ["if TYPE_CHECKING:", "raise NotImplementedError"]Configuration
Use pydantic-settings BaseSettings with an env prefix unique to the server.
from pydantic_settings import BaseSettings, SettingsConfigDict
class Settings(BaseSettings):
model_config = SettingsConfigDict(env_prefix="MY_SERVER_", env_file=".env", extra="ignore")
base_url: str = "https://api.example.com"
request_timeout: int = 30
auth_strategy: str = "oauth2"
secret_backend: str = "keychain"
max_retries: int = 3
backoff_base: float = 1.0
backoff_max: float = 60.0
rate_limit_rps: int = 10
default_limit: int = 25
max_limit: int = 500 # Enforced in every tool
log_level: str = "INFO"
user: str = os.environ.get("USER", "unknown")Rules: All fields must have sensible defaults. Safety limits (max_limit) must be defined and enforced in tools. Document every env var in the README configuration table.
Authentication
Define a Protocol. Implement concrete strategies. Select via factory.
class AuthManager(Protocol):
async def get_token(self, http_client: httpx.AsyncClient) -> str: ...
async def get_auth_headers(self, http_client: httpx.AsyncClient) -> dict[str, str]: ...
def invalidate(self) -> None: ...Rules:
- Cache tokens in memory with a 5-minute expiry buffer.
- Use
asyncio.Lockfor token refresh to prevent concurrent duplicate refreshes. - On 401, invalidate the token and retry once (let the retry loop handle it).
- Never log tokens. Exclude from
__repr__withrepr=False. - Support at least two strategies: one for local dev and one for testing (static token / env var).
Secrets Management
Three-tier strategy: macOS Keychain → AWS Secrets Manager → environment variables.
class SecretStore(Protocol):
def get_secret(self, key: str) -> str: ...
def set_secret(self, key: str, value: str) -> None: ...Rules:
- Use
keyringfor macOS Keychain. Default service name: the package name. - Use
boto3for AWS Secrets Manager. Cache the JSON blob in memory after first load. - Use env vars as fallback for CI/testing.
- Factory function selects backend:
create_secret_store(backend: str) -> SecretStore. - Never log secret values. Log key names at debug level only.
HTTP Client
Use httpx (async) with retry, rate limiting, and structured logging.
Retry
Use tenacity. Do not implement custom retry loops.
from tenacity import AsyncRetrying, retry_if_exception_type, stop_after_attempt, wait_exponential_jitter
class RetryableHTTPError(Exception):
def __init__(self, status_code: int, retry_after: float | None = None):
self.status_code = status_code
self.retry_after = retry_afterRetryable vs non-retryable:
| Status | Retryable | Action |
| 429 | Yes | Respect Retry-After header (supports both seconds and HTTP-date format), then backoff |
| 5xx | Yes | Exponential backoff with jitter |
| 401 | Yes (once) | Invalidate token, retry |
| 400, 403, 404 | No | Raise immediately |
| Timeout | No | Raise immediately (don't mask slow upstream) |
Rate Limiting
Token-bucket algorithm with burst support and asyncio.Lock. Tracks _tokens, _max_tokens, _last_refill — refill on each acquire call, sleep if bucket is empty.
VPN-Aware Error Detection
For internal services, detect VPN disconnection and surface a clear message:
def _is_vpn_error(exc: BaseException, url: str = "") -> bool:
domain_is_internal = any(d in url for d in _VPN_REQUIRED_DOMAINS)
if isinstance(exc, httpx.ConnectError):
if "name or service not known" in str(exc.__cause__).lower():
return domain_is_internal
if isinstance(exc, httpx.ConnectTimeout) and domain_is_internal:
return True
return FalseObservability
Structured Logging
Use structlog with JSON output to stderr. Configure with: merge_contextvars, add_log_level, TimeStamper(fmt="iso"), _redact_secrets, JSONRenderer.
Secret Redaction
Apply a redaction processor before JSON rendering:
_SENSITIVE_SUBSTRINGS = {"secret", "password", "token", "authorization", "cookie", "api_key"}
def _redact_secrets(logger: Any, method: str, event_dict: dict[str, Any]) -> dict[str, Any]:
for key in list(event_dict.keys()):
if any(s in key.lower() for s in _SENSITIVE_SUBSTRINGS):
event_dict[key] = "***REDACTED***"
return event_dictAudit Logging
Every tool call must produce a structured audit log entry with: timestamp, event="tool_call", tool, user, request_id (uuid per call, sent as X-Request-Id), duration_ms (wall clock), upstream_duration_ms (HTTP only, via contextvar), result_count, retry_count, status (success | error | zero_result).
Error Classification
Classify errors and return structured responses to the LLM:
class ErrorType(str, Enum):
VPN = "vpn"
AUTH = "auth"
TIMEOUT = "timeout"
RATE_LIMITED = "rate_limited"
NOT_FOUND = "not_found"
VALIDATION = "validation"
UPSTREAM = "upstream"Return: {"error": "...", "error_type": "vpn", "suggestion": "Connect to VPN and retry."}
Tool Design
Docstrings
Every tool must have: one-sentence description, Args section (every param with type, default, constraints), return description.
Input Validation
- Use type hints for automatic validation via FastMCP.
- Clamp limits server-side:
limit = min(limit, settings.max_limit). - Validate enum-like inputs against known values. Return structured validation errors, not raw API errors.
- Use Pydantic models for complex dict inputs (create/update operations).
Return Types
- All tools return
dict[str, Any]. - Strip internal-only fields from upstream API responses before returning.
- Return structured error dicts on failure — never raise raw exceptions to the LLM.
- Include metadata (total count, pagination) when relevant.
Resources and Prompts
MCP defines three server-side primitives. Use the right one:
| Primitive | Initiated by | Always in context? | Use for |
| Tool | Agent | ✅ descriptions always sent | Actions, queries, APIs |
| Resource | App/client | ❌ fetched on demand | Reference docs, schemas, static context |
| Resource template | App/client | ❌ agent fills URI params | Parameterized reference data |
| Prompt | User | ❌ user invokes via UI | Workflow bootstrapping |
Server instructions | Always | ✅ always sent | ≤200-word server orientation |
Key rule: If the agent should independently decide to call it, use a tool. If the host/user/app controls when it appears, use a resource or prompt.
Resources
URI design: Use a custom scheme per RFC 3986 (myapp://path/to/resource). Keep URIs stable. Use {param} for templates (myapp://docs/{slug}). Concrete resources appear in resources/list; templates appear in resources/templates/list only.
Every resource and template must have a name, description, and MIME type (text/markdown, application/json, etc.). Use annotations={"audience": ["assistant"], "priority": 0.8} to signal relevance. Keep payloads under ~8 KB.
Path traversal prevention — always resolve and validate template params before reading from disk:
BASE_DIR = Path(__file__).parent / "docs"
@mcp.resource("myapp://docs/{slug}")
def get_doc(slug: str) -> str:
path = (BASE_DIR / slug).resolve()
if not str(path).startswith(str(BASE_DIR)):
raise McpError(ErrorCode.INVALID_PARAMS, "Invalid slug")
if not path.exists():
raise McpError(ErrorCode.RESOURCE_NOT_FOUND, f"No doc: {slug}")
return path.read_text()Error codes: not found → -32002, invalid params → -32602, read failure → -32603.
Resources must never expose credentials, API keys, or internal hostnames.
Prompts
Use prompts for user-initiated workflow starters — not as substitutes for tool docstrings. They appear as named entry points in the client UI.
@mcp.prompt(name="investigate", description="Start a root cause investigation.")
def investigate_prompt(metric: str, tenant: str = "", window: str = "1h") -> list[dict]:
return [{"role": "user", "content": f"Investigate `{metric}` over the last {window}..."}]Rules: Keep arguments minimal and optional where possible. All params must be str. End with a user turn — this tells the LLM what to do next. Never embed secrets or environment-specific values. Sanitize all argument values before including in message content.
Client Support
| Client | Resources | Prompts |
| Claude Desktop | ✅ Full | ✅ Full |
| VS Code Copilot | ✅ Full | ✅ Slash commands |
| Cursor | ⚠️ Partial | ⚠️ Partial |
Design for progressive enhancement: core functionality must work via tools alone.
Testing
Stack
- pytest + pytest-asyncio (auto mode)
- respx for httpx mocking
- pytest-cov with 85% minimum threshold
Test Structure
| Test file | Covers |
test_server.py | Tool dispatch, lifespan, AppContext wiring |
test_client.py | Retry on 5xx/429, 401 token refresh, rate limiting, timeout |
test_auth.py | Token acquisition, caching, expiry, refresh, concurrent lock |
test_secrets.py | All backends (keychain mocked, AWS mocked, env) |
test_config.py | Default values, env override, validation |
test_observability.py | Secret redaction, audit log structure, error classification |
Shared Fixtures (conftest.py)
@pytest.fixture
def settings() -> Settings:
return Settings(
base_url="https://api.test.example.com",
secret_backend="env",
request_timeout=10,
max_retries=2,
rate_limit_rps=100,
user="test-user",
)Integration tests: marked @pytest.mark.integration, skipped by default, require credentials, use read-only operations only.
Documentation
README.md: one-liner description → quick start (clone, sync, test) → VS Code / Claude config (copy-paste) → tools table → env var config table → dev commands → links to docs/.
ONBOARDING.md: prerequisites → install → credential setup → verification → IDE integration → troubleshooting table.
docs/DESIGN.md: problem statement → goals/non-goals → architecture diagram → module responsibilities → key decisions with rationale → tool contracts → testing strategy.
docs/SECURITY.md: secrets management → network requirements → redaction policy → input validation scope → OWASP alignment.
MCP config template (configs/mcp/<server-name>.json):
{
"name": "<server-name>",
"transport": "stdio",
"command": "uv",
"args": ["--directory", "~/code/<server-name>", "run", "python", "-m", "<package_name>"],
"env": { "<PREFIX>_SECRET_BACKEND": "keychain", "<PREFIX>_LOG_LEVEL": "INFO" }
}Security Checklist
- Secrets stored in Keychain or AWS Secrets Manager (never plaintext config files)
- Secret redaction processor in logging pipeline
repr=Falseon all credential fields in dataclasses- No secret values in error messages
- Rate limiting enabled (prevents upstream abuse)
- Timeouts on all HTTP requests
- Input validation at tool boundary (clamp limits, validate enums)
- HTTPS for all upstream connections
- VPN error detection for internal services
- Path traversal validation on any file-system resources
- No shell command execution from user inputs
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

