{"id":34599241,"url":"https://github.com/niradler/mcp-template-py","last_synced_at":"2026-05-27T02:34:54.971Z","repository":{"id":316933965,"uuid":"1065382298","full_name":"niradler/mcp-template-py","owner":"niradler","description":"A comprehensive template for creating MCP (Model Context Protocol) servers in Python using FastMCP","archived":false,"fork":false,"pushed_at":"2025-09-27T21:09:33.000Z","size":110,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-05-27T02:34:30.761Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/niradler.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-27T16:01:41.000Z","updated_at":"2025-09-27T21:09:36.000Z","dependencies_parsed_at":"2025-09-27T18:33:52.578Z","dependency_job_id":null,"html_url":"https://github.com/niradler/mcp-template-py","commit_stats":null,"previous_names":["niradler/mcp-template-py"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/niradler/mcp-template-py","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niradler%2Fmcp-template-py","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niradler%2Fmcp-template-py/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niradler%2Fmcp-template-py/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niradler%2Fmcp-template-py/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/niradler","download_url":"https://codeload.github.com/niradler/mcp-template-py/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/niradler%2Fmcp-template-py/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33548246,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-27T02:00:06.184Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-12-24T12:07:51.177Z","updated_at":"2026-05-27T02:34:54.954Z","avatar_url":"https://github.com/niradler.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MCP Server Template\n\nA clean, simple template for creating MCP (Model Context Protocol) servers in Python using FastMCP.\n\n## 🚀 Features\n\n- ✅ **FastMCP Framework** - Simple decorator-based API\n- ✅ **Complete MCP Support** - Prompts, Tools, and Resources\n- ✅ **Context Logging** - Proper logging through MCP context\n- ✅ **Input Validation** - Safe input handling and sanitization\n- ✅ **Comprehensive Testing** - Unit tests with pytest\n- ✅ **Production Ready** - Clean, maintainable code structure\n\n## 🎯 What's Included\n\n### Tools\n\n- **echo** - Basic tool demonstrating input validation and logging\n- **advanced_calculator** - Advanced tool with progress tracking and structured logging\n\n### Prompts\n\n- **hello_world** - Simple greeting prompt\n- **code_review** - Code review prompt generator\n\n### Resources\n\n- **server://info** - Server information and metadata\n- **server://status** - Current server status and metrics\n\n## 🚀 Quick Start\n\n1. **Install dependencies:**\n\n   ```bash\n   uv sync\n   ```\n\n2. **Run the server:**\n\n   ```bash\n   # stdio transport (default)\n   uv run python -m mcp_template.main\n\n   # SSE transport\n   uv run python -m mcp_template.main --transport sse --port 8000\n\n   # HTTP transport\n   uv run python -m mcp_template.main --transport http --port 8000\n   ```\n\n3. **Test with MCP Inspector:**\n   ```bash\n   npx @modelcontextprotocol/inspector uv run python -m mcp_template.main\n   ```\n\n## 🧪 Testing\n\nRun the test suite:\n\n```bash\nuv run pytest\n```\n\nRun with coverage:\n\n```bash\nuv run pytest --cov=src/mcp_template --cov-report=html\n```\n\n## 📁 Project Structure\n\n```\nsrc/mcp_template/\n├── __init__.py          # Package initialization\n├── main.py              # CLI entry point with transport options\n├── server.py            # FastMCP server setup\n├── tools.py             # Tool implementations (your main work area)\n├── prompts.py           # Prompt implementations\n├── resources.py         # Resource implementations\n└── helpers/\n    ├── __init__.py      # Helper exports\n    ├── logging.py       # MCP context logger\n    └── validation.py    # Input validation utilities\n```\n\n## 🛠️ Development\n\n### Adding New Tools\n\nEdit `src/mcp_template/tools.py`:\n\n```python\n@mcp.tool()\nasync def my_tool(input_data: str, ctx: Context[ServerSession, Any] = None) -\u003e str:\n    \"\"\"My custom tool.\"\"\"\n    if ctx:\n        logger = Logger(ctx, \"my_tool\")\n        await logger.info(\"Tool started\")\n\n    # Your logic here\n    result = f\"Processed: {input_data}\"\n\n    if ctx:\n        await logger.info(\"Tool completed\")\n\n    return result\n```\n\n### Adding New Prompts\n\nEdit `src/mcp_template/prompts.py`:\n\n```python\n@mcp.prompt()\ndef my_prompt(topic: str, style: str = \"professional\") -\u003e str:\n    \"\"\"Generate a prompt about a topic.\"\"\"\n    return f\"Write about {topic} in a {style} style...\"\n```\n\n### Adding New Resources\n\nEdit `src/mcp_template/resources.py`:\n\n```python\n@mcp.resource(\"my://resource\")\ndef my_resource() -\u003e str:\n    \"\"\"My custom resource.\"\"\"\n    return json.dumps({\"message\": \"Hello from my resource\"})\n```\n\n## 🔧 Configuration\n\nThe server uses FastMCP's automatic configuration. For custom settings, modify `src/mcp_template/server.py`.\n\n## 📝 Logging\n\nThe template includes a Logger class that sends messages to MCP clients using the [official MCP logging approach](https://github.com/modelcontextprotocol/python-sdk):\n\n```python\nfrom .helpers import Logger\n\n# In your tool function\nif ctx:\n    logger = Logger(ctx, \"component_name\")\n    await logger.info(\"Processing started\", extra={\"user_id\": 123})\n    await logger.debug(\"Debug information\")\n    await logger.warning(\"Warning message\")\n    await logger.error(\"Error occurred\", extra={\"error_code\": \"E001\"})\n```\n\nThe Logger automatically formats messages with component names and handles structured logging with extra data. It gracefully handles test environments where context may not be available.\n\n## 🚀 Deployment\n\nFor production deployment:\n\n1. Build with uv:\n\n   ```bash\n   uv build\n   ```\n\n2. Install the built package:\n\n   ```bash\n   pip install dist/mcp_template-*.whl\n   ```\n\n3. Run:\n   ```bash\n   python -m mcp_template.main\n   ```\n\n## 📚 FastMCP Documentation\n\nFor more information about FastMCP features, visit:\n\n- [FastMCP Documentation](https://gofastmcp.com/)\n- [MCP Specification](https://spec.modelcontextprotocol.io/)\n\n## 🤝 Contributing\n\n1. Fork the repository\n2. Create a feature branch\n3. Make your changes\n4. Add tests for new functionality\n5. Run the test suite\n6. Submit a pull request\n\n## 📄 License\n\nMIT License - see LICENSE file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fniradler%2Fmcp-template-py","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fniradler%2Fmcp-template-py","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fniradler%2Fmcp-template-py/lists"}