Skip to main content
Glama
GSA-TTS

MCP Hackathon Server

Official
by GSA-TTS

GSA MCP 黑客马拉松 — 服务器模板

一个即用型入门项目,用于在 Python 中构建 Model Context Protocol (MCP) 服务器,并附带 IBM Cloud (watsonx Orchestrate) 和 Databricks 的部署套件。

基于 FastMCP 和 uv 构建。如果你从未构建过 MCP 服务器,请从 QUICKSTART.md 开始。


什么是 MCP 服务器?

MCP 服务器向 AI 客户端(如 Claude Desktop、Claude Code 或 watsonx Orchestrate 等代理平台)暴露 工具(模型可调用的函数)、提示词(可复用的对话开场白)和 资源(模型可读取的数据)。你编写工具;客户端的模型决定何时调用它们。

本模板为你提供了一个包含各类示例各一个的可运行服务器,因此你可以用自有服务替换这些示例并进行部署。


Related MCP server: Python MCP Server Template

仓库结构

mcp-hackathon-template/
├── README.md                  # This file
├── QUICKSTART.md              # 5-minute clone → run → connect walkthrough
├── main.py                    # Local entry point (uv run python main.py)
├── pyproject.toml             # Package + dependencies (uv)
├── requirements.txt           # Mirror of runtime deps (for buildpack hosts)
├── Dockerfile                 # Container image (streamable-HTTP, port 8080)
├── manifest.yaml              # cloud.gov (Cloud Foundry) deploy
├── server.json                # MCP registry metadata
├── .env.example               # Copy to .env for local dev
├── .github/workflows/ci.yml   # Lint + test on push/PR
├── src/
│   └── example_server/        # ← rename to your service
│       ├── app.py             # Thin entry point: builds FastMCP, picks transport
│       ├── config.py          # Settings from env vars / .env
│       ├── models.py          # Pydantic models & enums for tool params
│       ├── utils.py           # Shared helpers (HTTP client, pagination)
│       ├── routes.py          # HTTP-only routes (/health, /version)
│       ├── tools/             # ONE FILE PER TOOL
│       │   ├── __init__.py    #   register_tools(mcp) aggregator
│       │   └── example_tool.py
│       ├── prompts/
│       │   ├── __init__.py    #   register_prompts(mcp) aggregator
│       │   └── example.py
│       └── resources/
│           ├── __init__.py    #   register_resources(mcp) aggregator
│           └── example.py
├── tests/                     # Import + registration smoke tests
├── eval/                      # Stub → build a Phoenix eval harness (see mcp-eval skill)
└── deploy/
    ├── README.md              # Which deployment kit to use
    ├── ibm/                   # watsonx Orchestrate: 3 kits (see below)
    └── databricks/            # Databricks Apps kit

快速开始

前置条件

  • uv — pip install uv 或 brew install uv

安装并运行

cp .env.example .env
uv sync
uv run python main.py

服务器以 stdio 模式启动 — 它通过 stdin/stdout 进行 JSON-RPC 通信,这正是本地客户端(Claude Desktop、Claude Code)启动它的方式。参见 QUICKSTART.md 以连接客户端。

验证

uv sync --group dev
uv run pytest tests/ -v      # tests
uv run ruff check .          # lint

一工具一文件的模式

每个工具都位于 src/example_server/tools/ 下的独立文件中,并暴露一个 register(mcp) 函数。tools/__init__.py 通过单个 register_tools(mcp) 调用每个工具。这样可以让工具列表一目了然,并且只需改动两个文件即可添加或移除一个集成。

第 1 步 — 创建 src/example_server/tools/my_tool.py:

from typing import Annotated
from fastmcp import FastMCP

from example_server.utils import fetch_json


def register(mcp: FastMCP) -> None:
    @mcp.tool(
        name="example_get_thing",
        annotations={
            "title": "Get a thing",
            "readOnlyHint": True,
            "destructiveHint": False,
            "idempotentHint": True,
            "openWorldHint": True,
        },
    )
    async def get_thing(thing_id: Annotated[str, "The ID to fetch."]) -> dict:
        """One-line summary. Document the data source, its update cadence,
        and the return shape here — the model reads this docstring."""
        return await fetch_json(f"https://api.example.gov/things/{thing_id}")

第 2 步 — 在 tools/__init__.py 中接线:

from example_server.tools import example_tool, my_tool

def register_tools(mcp) -> None:
    example_tool.register(mcp)
    my_tool.register(mcp)  # ← add this line

第 3 步 — 在 config.py 中添加任何 API 密钥作为类型化字段,并在 .env.example 中记录该环境变量。

提示词(prompts/)和资源(resources/)遵循完全相同的 register(mcp) + 聚合器模式。


重命名包

在发布服务器之前,将 example_server 重命名为你的服务名(例如 census_mcp):

  1. 将文件夹 src/example_server/ 重命名为 src/<your_name>/。

  2. 更新 pyproject.toml:[project].name、[project].scripts 和 [tool.hatch.build.targets.wheel].packages。

  3. 在 src/、tests/、main.py、Dockerfile 和 manifest.yaml 中查找并替换 example_server。


工具设计建议(面向联邦数据)

  • 返回结构化数据,而非散文。 返回键一致的字典/列表,让模型自行叙述。

  • 注明数据新鲜度。 联邦数据集存在滞后;在 docstring 中说明更新频率和“截至”日期。

  • 暴露分页。 使用 utils.py 中的 PaginationParams / paginate(),并返回 has_more / next_offset。

  • 使用显式超时。 utils.fetch_json 默认超时为 30 秒。

  • 可操作性的错误。 返回带有 hint 的错误字典,而不是原始堆栈跟踪。


部署

本地开发使用 stdio。要将服务器共享给代理平台,请部署并注册它。参见 deploy/README.md 以选择方案,然后:

  • IBM watsonx Orchestrate — deploy/ibm/(三套方案:本地 stdio 工具包、Code Engine 从 Git 构建、以及预构建镜像)。

  • Databricks Apps — deploy/databricks/。

两者读取相同的服务器代码;当平台注入端口时,app.py 会自动提供 HTTP 服务。


评估

衡量 LLM 使用你的工具的能力,才是对服务器质量的真正考验。本模板有意不附带评估工具 — 参见 eval/README.md 以了解如何使用 mcp-eval 技能构建评估工具。


许可证

MIT。参见 SECURITY.md 了解漏洞披露政策和黑客马拉松安全注意事项。

Available Tools

1 tool
example_search_datasetsSearch Datasets (example)B
Read-onlyIdempotent

Search federal datasets matching a query string. (STUB — replace me.)

This stub shows the shape of a real tool without calling a live API. Swap the body for an actual request using fetch_json(...); a worked pattern is included below in a comment.

ParametersJSON Schema
NameRequiredDescriptionDefault
queryYesKeywords to search dataset titles and descriptions.
paginationNoOptional limit/offset (defaults to limit=20, offset=0).
response_formatNoReturn machine-readable JSON (default) or human-readable Markdown.json

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

B3.1/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The annotations (readOnlyHint, openWorldHint, idempotentHint, destructiveHint: false) already establish the safety profile. The description adds one meaningful behavioral fact—'This stub... without calling a live API'—which is honest and useful context. However, it doesn't elaborate on return behavior, result ordering, or error conditions, leaving most of the behavioral burden on the annotations. No contradiction with the annotations is present.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The text is short and front-loads the meaningful description, which is good. However, roughly three of four lines are implementer-facing stub notes ('(STUB — replace me.)', 'Swap the body...', 'a worked pattern is included below in a comment') that add no value to an agent selecting or invoking the tool. It's not verbose, but those sentences could earn their place better with functional detail.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the presence of an output schema, return values don't need explanation. The schema plus annotations cover the mechanical calling contract well. However, the description leaves open real-world questions an agent might face, such as what 'federal datasets' covers, and pagination behavior. For an explicitly stubbed example tool, this is adequate, but not complete for a production tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, and the schema thoroughly documents all three parameters: the required 'query', the pagination object with limits and defaults, and the response_format enum with its default. Per calibration rules, the baseline is 3 when the schema covers everything. The description itself adds no parameter-level insight, which is acceptable at this coverage level.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The opening sentence 'Search federal datasets matching a query string' uses a specific verb and resource, so an agent immediately knows what the tool does. The remaining stub text is implementer-oriented but does not obscure the purpose. It earns a 4 because it's clear on function, though the nonsensical stub placeholder text prevents a 5.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

There is no guidance on when to use this tool versus alternatives, what input it expects conceptually (beyond schema), or any prerequisites or limitations. The stub text discusses implementation ('Swap the body for an actual request') rather than agent-facing usage. While the absence of sibling tools lowers the need for differentiation, the description still provides no real usage context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 1 tool updatev0.1.0
    • First observedexample_search_datasets

TDQS

B3.1/5.0

Scored across 1 tool

Disambiguation5/5

Only one tool exists, so there is no possibility of confusion or overlap. The sole tool has a clear, singular purpose.

Naming Consistency5/5

With a single tool, there is no inconsistency in naming conventions. The name follows a verb_noun pattern (search_datasets).

Tool Count1/5

A single stub tool is a trivial surface for a server, far below the typical 3-15 tool range. It does not constitute a meaningful tool set.

Completeness1/5

The server is explicitly a stub with no real functionality, offering only a placeholder search. It has no coverage of any actual domain or workflow.

Maintenance

ActivityMaintained
ResponsivenessUnresponsive

Related MCP Connectors

Related MCP Servers

  • F
    license
    Not graded
    quality
    D
    maintenance
    A basic MCP server template that provides a foundation for building custom tools, resources, and prompts. Serves as a starting point for developers to create their own MCP server functionality.
    -
  • F
    license
    Not graded
    quality
    D
    maintenance
    A foundational template for building MCP servers in Python using Streamable HTTP transport. Provides example implementations of tools, resources, and prompts to help developers create custom MCP integrations for AI assistants.
    -
  • A
    license
    Not graded
    quality
    D
    maintenance
    A minimal template MCP server demonstrating basic tools, resources, and prompts functionality. Includes example implementations like a hello tool, history resource, and greet prompt for learning MCP development.
    0
    ISC