Create

Sign in to ReadmeX

or

How we handle your data: Privacy Policy

ReadmeX

Your AI reading companion

What would you like to catch up on?

Pick a briefing, or ask your own question.

Your community and people briefings stay personal to you.

Story

Internal MCP Servers reportedly cut timeout rate to 0.3%

AI summary

An engineering account describes a two-week rewrite of the transport layers of six internal MCP Servers serving orders, inventory, work orders, reporting, permissions and logging. The author reports that asynchronous tools, layered timeouts, SSE heartbeats and paginated responses reduced the client-side timeout rate from 12% to 0.3% and P99 latency from 40 seconds to 1.1 seconds. The account also describes using ContextVar for request state and handling stdio EOF. These results are self-reported and have not been independently verified.

In-depth insight

The account documents concrete implementation changes and staged measurements for reducing MCP client timeouts and latency in an internal deployment. The findings remain an unverified case study, and the author says results may depend on the deployment environment.

把 6 个内部 MCP Server 重写一遍传输层:超时率从 12% 降到 0.3% 的工程记录

我们团队内部有 6 个 MCP Server,分别对接订单、库存、工单、报表、权限和日志系统。上线三个月,客户端侧的超时率一直稳定在 12% 左右,每天有几十次工具调用直接失败,Agent 只能重试或者放弃。

我用了两周时间把这 6 个 Server 的传输层全部重写了一遍,超时率降到 0.3%。这篇文章不讲概念,只讲我们做了什么改动、为什么这么改、改完之后数据变成什么样。

起点:我们最初的服务端长什么样

第一版是照着 2024 年底的教程写的,每个 Server 一个 SSEServerTransport,工具函数全是同步函数,日志用 print,超时统一设 60 秒。

# 第一版:问题都在这 20 行里
from mcp.server.fastmcp import FastMCP

mcp = FastMCP("order")

@mcp.tool()
def query_order(order_id: str) -> dict:      # 同步函数
    print(f"query {order_id}")               # 污染 stdout
    resp = requests.get(f"http://api/orders/{order_id}")  # 阻塞
    return resp.json()

#MCP#FastMCP#NGINX#httpx#AnyIO

Original · 6 min readRead the original
Group chat

No comments yet. Start the conversation.