跳到正文
DEV Community· Elliot Marsh·· 39 分鐘前AI 評分57

TableJourney 在靜態網站旁建置 MCP 伺服器,並展示 Agent 實際調用哪些工具

An MCP server beside a static site: what we built and what agents actually call

AI 導讀

TableJourney 在靜態網站旁增設 REST API 和 MCP 伺服器,相應端點與工具共用同一 Python 函式。30 天日誌顯示,探索流量約為實際工具調用的 40 倍;場地搜尋是實際調用最多的工具。作者建議按方法統計調用,並讓 initialize 和 tools/list 快速回應,以分辨探索請求與實際使用。

正文

Our site is static: Python generates HTML from a database and the pages are served as files. When AI assistants started sending readers to us, we wanted them to get structured answers instead of scraping pages, so we added two doors to the same data: a REST API and a Model Context Protocol (MCP) server. This post covers how they sit beside a static site, the design choices that mattered, and what a month of logs says about who actually uses them.

One function, two doors

The rule that saved the most time: every MCP tool calls the same function as the matching REST endpoint. The festival search, for example, is one Python function; REST wraps it at /api/v1/festivals and MCP exposes it as the festivals tool. Nothing about the data is duplicated, so the two can never disagree.

The service is a small Python app with its own image. A reverse proxy sends /api/v1, /mcp and a few other paths to it and everything else to the static file server, so the site itself stays static and the API can be deployed on its own.

The MCP side

We use the official Python SDK with the streamable HTTP transport. A tool is a function with typed, described parameters:

RO = ToolAnnotations(read_only_hint=True, destructive_hint=False,
                     idempotent_hint=True, open_world_hint=False)

@server.tool(
    name="festivals",
    title="Find food festivals",
    annotations=RO,
    description=(
        "Food festivals with their next resolved dates (read-only). Filter by city, "
        "country, a date window and text. Each item carries starts_on/ends_on for the "
        "next edition, the organiser source URL and the page to cite."
    ),
)
def t_festivals(
    ctx: Context,
    country: Annotated[str | None, Field(description="Country slug or name, e.g. 'italy'.")] = None,
    city: Annotated[str | None, Field(description="City slug or name.")] = None,
    date_from: Annotated[str | None, Field(description="Earliest end date, ISO.")] = None,
    date_to: Annotated[str | None, Field(description="Latest start date, ISO.")] = None,
    query: Annotated[str | None, Field(description="Free text: festival name, food or drink.")] = None,
    limit: Annotated[int, Field(ge=1)] = 20,
) -> list[dict]:
    return find_festivals(country=country, city=city, date_from=date_from,
                          date_to=date_to, query=query, limit=min(limit, 100))

Three choices made a visible difference:

  • Read-only annotations. Every tool is a read, and saying so lets clients call them without asking the user to approve each call.
  • Parameter descriptions that carry examples. Models fill parameters better when the description says "a slug or a name, e.g. 'italy'". We also accept names and answer an unknown city with did_you_mean instead of an empty list.
  • Server instructions. The server's instructions string is a short guide: which tool to call first for "what can I do in this city", that results carry a page to cite, and the terms of use. Clients pass it to the model with the tool list, so it is the one place to explain how the tools fit together.

The server runs stateless, which suits a fleet of identical containers behind a load balancer. You can try the handshake with curl:

curl -s -X POST https://tablejourney.com/mcp \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json, text/event-stream' \
  -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"curl","version":"1"}}}'

It answers with the server's capabilities and its instructions. In Claude Code it is one line:

claude mcp add --transport http tablejourney https://tablejourney.com/mcp

Every answer cites a page

Each result includes the URL of the page it came from, and the instructions ask the assistant to cite it. That is good for the reader (they can check our sources) and for us (the assistant links to the page). Our pages carry the provenance, the date each fact was checked and the source, so a cited answer can be verified by a person.

Logging every call, carefully

We log each call with the tool name, the declared parameters only, the result count, the time taken and the client name from the handshake. Logging only declared parameters keeps arbitrary input out of the logs. Rate limits are counted in the database, not in memory, so they hold across every running copy.

What 30 days of logs say

This is the part I did not expect. Over the last 30 days the server saw roughly:

Call Count
tools/list 9,800
initialize 7,900
resources/list, prompts/list 2,900 each
ping 840
actual tool calls about 200

Most traffic is discovery: MCP directories and health checkers connecting, listing tools and leaving. The top client names in the handshake are directory probes, not assistants. Discovery outnumbers real use by roughly forty to one.

Among the real tool calls, the order was clear: search_places (venue search) first, then place (one venue in full), then festivals, cities and dishes. People ask assistants where to eat far more often than anything else, and the "what is on while I am there" question comes next.

Three lessons from that:

  1. Make discovery cheap. initialize and tools/list should be fast and never touch the database. Most of your traffic will be exactly those calls.
  2. Count calls by method. If you only count requests, the directories hide your real usage.
  3. Lead with the search tool. The tool most calls go to deserves the best description and the most forgiving parameters.

REST is still busier

The REST API sees more real use than MCP: venue search, the OpenAPI docs and the festival search are its top endpoints. Developers try an API with curl before they wire it into anything. Keep both, and keep them on one function.

Discovery files

Agents and their developers find a server through a few small files: an llms.txt that describes the site, a /.well-known/ manifest for the MCP server, an OpenAPI description, and an API catalog (RFC 9727) linked from an HTTP Link header. Each takes minutes to add and they are how most of those directory probes found us.

The full tool list and setup steps for nine clients are at https://tablejourney.com/agents/. If you run an MCP server, I would like to know whether your discovery to use ratio looks like ours.

來源:DEV Community · dev.to