Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connect failed because uri prefix have 2 "/" #40

Open
StephenZeng-Wonder opened this issue Feb 8, 2025 · 1 comment
Open

connect failed because uri prefix have 2 "/" #40

StephenZeng-Wonder opened this issue Feb 8, 2025 · 1 comment
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@StephenZeng-Wonder
Copy link

Describe the bug
I set the git mcp server up with sse, and test with MCP Inspector success

Image

the server log:

INFO:mcp_server_git.server:Using repository at D:\core-ai
DEBUG:mcp.server.lowlevel.server:Initializing server 'mcp-git'
DEBUG:mcp.server.lowlevel.server:Registering handler for ListToolsRequest
DEBUG:mcp.server.lowlevel.server:Registering handler for CallToolRequest
DEBUG:mcp.server.sse:SseServerTransport initialized with endpoint: /messages
DEBUG:asyncio:Using proactor: IocpProactor
INFO:     Started server process [19820]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:8080 (Press CTRL+C to quit)
DEBUG:mcp.server.sse:Setting up SSE connection
DEBUG:mcp.server.sse:Created new session with ID: af34aa1e-7e21-4853-b3ff-48ec6448db03
DEBUG:mcp.server.sse:Starting SSE response task
DEBUG:mcp.server.sse:Yielding read and write streams
INFO:     127.0.0.1:63784 - "GET / HTTP/1.1" 200 OK
DEBUG:mcp.server.sse:Starting SSE writer
DEBUG:mcp.server.sse:Sent endpoint event: /messages?session_id=af34aa1e7e214853b3ff48ec6448db03
DEBUG:sse_starlette.sse:chunk: b'event: endpoint\r\ndata: /messages?session_id=af34aa1e7e214853b3ff48ec6448db03\r\n\r\n'
INFO:     127.0.0.1:63786 - "POST /messages?session_id=af34aa1e7e214853b3ff48ec6448db03 HTTP/1.1" 307 Temporary Redirect
DEBUG:mcp.server.sse:Handling POST message
DEBUG:mcp.server.sse:Parsed session ID: af34aa1e-7e21-4853-b3ff-48ec6448db03
DEBUG:mcp.server.sse:Received JSON: {'jsonrpc': '2.0', 'id': 0, 'method': 'initialize', 'params': {'protocolVersion': '2024-11-05', 'capabilities': {'sampling': {}, 'roots': {'listChanged': True}}, 'clientInfo': {'name': 'mcp-inspector', 'version': '0.0.1'}}}
DEBUG:mcp.server.sse:Validated client message: root=JSONRPCRequest(method='initialize', params={'protocolVersion': '2024-11-05', 'capabilities': {'sampling': {}, 'roots': {'listChanged': True}}, 'clientInfo': {'name': 'mcp-inspector', 'version': '0.0.1'}}, jsonrpc='2.0', id=0)
DEBUG:mcp.server.sse:Sending message to writer: root=JSONRPCRequest(method='initialize', params={'protocolVersion': '2024-11-05', 'capabilities': {'sampling': {}, 'roots': {'listChanged': True}}, 'clientInfo': {'name': 'mcp-inspector', 'version': '0.0.1'}}, jsonrpc='2.0', id=0)
INFO:     127.0.0.1:63787 - "POST /messages/?session_id=af34aa1e7e214853b3ff48ec6448db03 HTTP/1.1" 202 Accepted
DEBUG:mcp.server.sse:Sending message via SSE: root=JSONRPCResponse(jsonrpc='2.0', id=0, result={'protocolVersion': '2024-11-05', 'capabilities': {'experimental': {}, 'tools': {'listChanged': False}}, 'serverInfo': {'name': 'mcp-git', 'version': '1.2.1'}})
DEBUG:sse_starlette.sse:chunk: b'event: message\r\ndata: {"jsonrpc":"2.0","id":0,"result":{"protocolVersion":"2024-11-05","capabilities":{"experimental":{},"tools":{"listChanged":false}},"serverInfo":{"name":"mcp-git","version":"1.2.1"}}}\r\n\r\n'
INFO:     127.0.0.1:63786 - "POST /messages?session_id=af34aa1e7e214853b3ff48ec6448db03 HTTP/1.1" 307 Temporary Redirect
DEBUG:mcp.server.sse:Handling POST message
DEBUG:mcp.server.sse:Parsed session ID: af34aa1e-7e21-4853-b3ff-48ec6448db03
DEBUG:mcp.server.sse:Received JSON: {'jsonrpc': '2.0', 'method': 'notifications/initialized'}
DEBUG:mcp.server.sse:Validated client message: root=JSONRPCNotification(method='notifications/initialized', jsonrpc='2.0', params=None)
DEBUG:mcp.server.sse:Sending message to writer: root=JSONRPCNotification(method='notifications/initialized', jsonrpc='2.0', params=None)
INFO:     127.0.0.1:63787 - "POST /messages/?session_id=af34aa1e7e214853b3ff48ec6448db03 HTTP/1.1" 202 Accepted
DEBUG:mcp.server.lowlevel.server:Received message: root=InitializedNotification(method='notifications/initialized', params=None, jsonrpc='2.0')
DEBUG:sse_starlette.sse:ping: b': ping - 2025-02-08 03:39:43.843539+00:00\r\n\r\n'

but use kotlin-sdk connect failed:

server log:

DEBUG:mcp.server.sse:Setting up SSE connection
DEBUG:mcp.server.sse:Created new session with ID: 592f37fb-6b75-4df1-ac4e-e399d15a59c1
DEBUG:mcp.server.sse:Starting SSE response task
DEBUG:mcp.server.sse:Yielding read and write streams
INFO:     127.0.0.1:49914 - "GET / HTTP/1.1" 200 OK
DEBUG:mcp.server.sse:Starting SSE writer
DEBUG:mcp.server.sse:Sent endpoint event: /messages?session_id=592f37fb6b754df1ac4ee399d15a59c1
DEBUG:sse_starlette.sse:chunk: b'event: endpoint\r\ndata: /messages?session_id=592f37fb6b754df1ac4ee399d15a59c1\r\n\r\n'
INFO:     127.0.0.1:49917 - "POST //messages?session_id=592f37fb6b754df1ac4ee399d15a59c1 HTTP/1.1" 404 Not Found

To Reproduce
Steps to reproduce the behavior:
client code:

    suspend fun connect(h: String, p: Int): Client {
        val client = Client(Implementation("test", "1.0.0"))
        val transport = HttpClient {
            install(io.ktor.client.plugins.sse.SSE)
        }.mcpSseTransport {
            url {
                host = h
                port = p
            }
        }
        client.connect(transport)
        return client
    }

Expected behavior
A clear and concise description of what you expected to happen.

Logs
If applicable, add logs to help explain your problem.

Additional context
Add any other context about the problem here.

@StephenZeng-Wonder StephenZeng-Wonder added the bug Something isn't working label Feb 8, 2025
@StephenZeng-Wonder
Copy link
Author

my workaround:


...
    # options = server.create_initialization_options()
    # async with stdio_server() as (read_stream, write_stream):
    #     await server.run(read_stream, write_stream, options, raise_exceptions=True)

    from mcp.server.sse import SseServerTransport
    from starlette.applications import Starlette
    from starlette.routing import Mount, Route

    sse = SseServerTransport("/messages/")

    async def handle_sse(request):
        async with sse.connect_sse(request.scope, request.receive, request._send) as streams:
            await server.run(streams[0], streams[1], server.create_initialization_options())

    starlette_app = Starlette(
        debug=True,
        routes=[
            Route("/", endpoint=handle_sse),
            Mount("/messages/", app=sse.handle_post_message),
            Mount("//messages/", app=sse.handle_post_message),
        ],
    )

    import uvicorn

    uvicorn.run(starlette_app, host="0.0.0.0", port=8080)

@e5l e5l added the good first issue Good for newcomers label Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants