一键导入
mcp-server
Specification for building Model Context Protocol servers using Python
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Specification for building Model Context Protocol servers using Python
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Commands, man-style CLI flags, and Microsoft.WSL.Containers API for building/running Linux containers via wslc on Windows (no Docker Desktop required).
Run the Antigravity (Gemini) CLI agent harness via the agy binary. Includes interactive session control and exit handling.
Use this skill whenever you need to click, type, or navigate inside a browser window (Edge, Chrome, Firefox, etc.) but the computer-use MCP blocks interaction because the browser is granted at tier 'read'. This skill bypasses that restriction by injecting mouse and keyboard input at the Windows API level via PowerShell and user32.dll—the same technique that worked to navigate Edge to code.visualstudio.com. Trigger this skill any time you see the error 'granted at tier read — visible in screenshots only, no clicks or typing', or any time the user asks you to click or type in a browser and the Claude-in-Chrome extension is not connected.
Python SDK for programmatic control of GitHub Copilot CLI via JSON-RPC
Harden Windows Defender privacy settings for authorized pentest engagements. Disables telemetry uploads, sample submission, and cloud reporting to prevent leaking target info, credentials, and tooling to Microsoft. Includes exclusion management and post-engagement re-enablement.
Configuration for OpenCode ACP Support - setting up OpenCode to work with ACP-compatible editors
| name | mcp-server |
| description | Specification for building Model Context Protocol servers using Python |
| author | Tim Sonner |
| license | MIT |
| compatibility | opencode |
| metadata | {"audience":"developers","workflow":"server-development","language":"python"} |
Based on the Model Context Protocol documentation for building servers.
MCP (Model Context Protocol) servers expose capabilities to LLM clients through three main types:
This specification focuses on building MCP servers using Python.
Important: For STDIO-based servers (most common), never write to stdout as it corrupts JSON-RPC messages.
# ❌ Bad (STDIO)
print("Processing request")
# ✅ Good (STDIO)
print("Processing request", file=sys.stderr)
# ✅ Good (STDIO)
logging.info("Processing request")
uv package manager recommended# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh
# Create project
uv init mcp-server
cd mcp-server
# Create virtual environment
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install dependencies
uv add "mcp[cli]" httpx
# Create server file
touch server.py
from typing import Any
import httpx
import logging
import sys
from mcp.server.fastmcp import FastMCP
# Initialize FastMCP server
mcp = FastMCP("server-name")
# Constants (example for weather API)
API_BASE = "https://api.example.com"
USER_AGENT = "mcp-server/1.0"
# Setup logging (write to stderr for STDIO servers)
logging.basicConfig(level=logging.INFO, stream=sys.stderr)
logger = logging.getLogger(__name__)
async def make_api_request(url: str) -> dict[str, Any] | None:
"""Make an API request with proper error handling."""
headers = {
"User-Agent": USER_AGENT,
"Accept": "application/json"
}
try:
async with httpx.AsyncClient() as client:
response = await client.get(url, headers=headers, timeout=30.0)
response.raise_for_status()
return response.json()
except Exception as e:
logger.error(f"Error making API request to {url}: {e}")
return None
@mcp.tool()
async def example_tool(param: str) -> str:
"""Example tool description.
Args:
param: Description of the parameter
"""
url = f"{API_BASE}/endpoint/{param}"
data = await make_api_request(url)
if not data:
return "Unable to fetch data."
# Process and format the data as needed
return f"Processed result: {data}"
def main():
"""Initialize and run the server."""
mcp.run(transport="stdio")
if __name__ == "__main__":
main()
Here's a complete implementation based on the MCP documentation:
from typing import Any
import httpx
import sys
from mcp.server.fastmcp import FastMCP
# Initialize FastMCP server
mcp = FastMCP("weather")
# Constants
NWS_API_BASE = "https://api.weather.gov"
USER_AGENT = "weather-app/1.0"
async def make_nws_request(url: str) -> dict[str, Any] | None:
"""Make a request to the NWS API with proper error handling."""
headers = {"User-Agent": USER_AGENT, "Accept": "application/geo+json"}
async with httpx.AsyncClient() as client:
try:
response = await client.get(url, headers=headers, timeout=30.0)
response.raise_for_status()
return response.json()
except Exception:
return None
def format_alert(feature: dict) -> str:
"""Format an alert feature into a readable string."""
props = feature["properties"]
return f"""
Event: {props.get("event", "Unknown")}
Area: {props.get("areaDesc", "Unknown")}
Severity: {props.get("severity", "Unknown")}
Description: {props.get("description", "No description available")}
Instructions: {props.get("instruction", "No specific instructions provided")}
"""
@mcp.tool()
async def get_alerts(state: str) -> str:
"""Get weather alerts for a US state.
Args:
state: Two-letter US state code (e.g. CA, NY)
"""
url = f"{NWS_API_BASE}/alerts/active/area/{state}"
data = await make_nws_request(url)
if not data or "features" not in data:
return "Unable to fetch alerts or no alerts found."
if not data["features"]:
return "No active alerts for this state."
alerts = [format_alert(feature) for feature in data["features"]]
return "\n---\n".join(alerts)
@mcp.tool()
async def get_forecast(latitude: float, longitude: float) -> str:
"""Get weather forecast for a location.
Args:
latitude: Latitude of the location
longitude: Longitude of the location
"""
# First get the forecast grid endpoint
points_url = f"{NWS_API_BASE}/points/{latitude},{longitude}"
points_data = await make_nws_request(points_url)
if not points_data:
return "Unable to fetch forecast data for this location."
# Get the forecast URL from the points response
forecast_url = points_data["properties"]["forecast"]
forecast_data = await make_nws_request(forecast_url)
if not forecast_data:
return "Unable to fetch detailed forecast."
# Format the periods into a readable forecast
periods = forecast_data["properties"]["periods"]
forecasts = []
for period in periods[:5]: # Only show next 5 periods
forecast = f"""
{period["name"]}:
Temperature: {period["temperature"]}°{period["temperatureUnit"]}
Wind: {period["windSpeed"]} {period["windDirection"]}
Forecast: {period["detailedForecast"]}
"""
forecasts.append(forecast)
return "\n---\n".join(forecasts)
def main():
# Initialize and run the server
mcp.run(transport="stdio")
if __name__ == "__main__":
main()
uv run server.py
opencode.json in your project root (or ~/.config/opencode/opencode.json for global config):
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"your-server-name": {
"type": "local",
"command": ["python3", "path/to/server.py"],
"enabled": true
}
}
}
Beyond tools, MCP servers can also provide:
@mcp.resource("resource://{type}/{id}")
def get_resource(type: str, id: str) -> str:
"""Access resource data."""
# Implementation
@mcp.prompt()
def analyze_data_prompt(data: str) -> str:
"""Analyze the provided data."""
return f"Please analyze this data and provide insights: {data}"
Specify these in your pyproject.toml:
[project]
name = "mcp-server"
dependencies = [
"mcp[cli]>=1.2.0",
"httpx>=0.25.0",
]
[project.optional-dependencies]
dev = [
"pytest>=7.0.0",
"black>=23.0.0",
"ruff>=0.1.0",
]