modelcontextprotocol / modelcontextprotocol/python-sdk
FastMCP server with SSE transport fails to shut down on a signal
オープン
まだ誰も着手していません。
bug
P3
ready for work
- 主要言語
- Python
- スター
- 24.3k
- フォーク
- 4k
- 平均マージ
- 1日 1時間
- マージ済み PR(30日)
- 31
説明
A very simple server fails to shut down on a signal if it processed at least one request:
❯ python test-server.py --port=8085
INFO: Started server process [216035]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:8085 (Press CTRL+C to quit)
INFO: 127.0.0.1:55188 - "GET /sse HTTP/1.1" 200 OK
INFO: 127.0.0.1:55192 - "POST /messages/?session_id=e690de9733914d09aebf2b0e8c78191c HTTP/1.1" 202 Accepted
INFO: 127.0.0.1:55192 - "POST /messages/?session_id=e690de9733914d09aebf2b0e8c78191c HTTP/1.1" 202 Accepted
INFO: 127.0.0.1:55192 - "POST /messages/?session_id=e690de9733914d09aebf2b0e8c78191c HTTP/1.1" 202 Accepted
Processing request of type CallToolRequest
^CINFO: Shutting down
INFO: Waiting for background tasks to complete. (CTRL+C to force quit)
The expected behaviour would be:
❯ python test-server.py --port=8085
INFO: Started server process [216006]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:8085 (Press CTRL+C to quit)
^CINFO: Shutting down
INFO: Waiting for application shutdown.
INFO: Application shutdown complete.
INFO: Finished server process [216006]
Here is the code for both the server and the client.
What do I miss?
the server
import click
import sys
from pydantic import Field
from mcp.server.fastmcp import FastMCP
@click.command()
@click.option("--port", default=8085, help="Port to listen", type=int)
def main(port: int):
mcp = FastMCP(
"mcp-echo-tool",
debug=True,
log_level="INFO",
port=port,
)
@mcp.tool(name="echo")
async def echo_tool(string: str = Field(description="A string to echo back")) -> str:
"""Echoes back the input string"""
return string
mcp.run(transport='sse')
return 0
if __name__ == "__main__":
sys.exit(main())
and the client
import asyncio
import click
import sys
from mcp.client.session import ClientSession
from mcp.client.sse import sse_client
async def client(url, string):
async with sse_client(url) as (read, write):
async with ClientSession(read, write) as session:
await session.initialize()
result = await session.call_tool("echo", {"string": string})
print(result.content)
@click.command()
@click.option('--url', default='http://localhost:8085', help='MCP Server URL', type=str)
@click.argument('string', type=str)
def main(url: str, string: str):
asyncio.run(client(url, string))
if __name__ == "__main__":
sys.exit(main())
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
提供された FastMCP SSE サーバーとクライアントを使ってシャットダウン動作を再現し、シグナルを送信する前にリクエストが処理されたことをまず確認します。次に、FastMCP SSE サーバーのライフサイクルと Uvicorn のシャットダウンパスを追跡します。完了の条件は、プロセスがアプリケーションのシャットダウンに到達し、2 回目のシグナルを必要とせずに終了することです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- api, backend
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 活発
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 48/100