Title: 401 Unauthorized · Issue #611 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: 401 Unauthorized · Issue #611 · modelcontextprotocol/python-sdk
X Title: 401 Unauthorized · Issue #611 · modelcontextprotocol/python-sdk
Description: Describe the bug Connecting from OpenAI SDK gives 401 Unauthorized, pretty sure #255 is related from 1.7.0 release. This worked with 1.6.0 To Reproduce Ubuntu 24.10 Python 3.12.7 pip install \ mcp==1.7.0 \ openai==1.76.2 \ openai-agents=...
Open Graph Description: Describe the bug Connecting from OpenAI SDK gives 401 Unauthorized, pretty sure #255 is related from 1.7.0 release. This worked with 1.6.0 To Reproduce Ubuntu 24.10 Python 3.12.7 pip install \ mcp=...
X Description: Describe the bug Connecting from OpenAI SDK gives 401 Unauthorized, pretty sure #255 is related from 1.7.0 release. This worked with 1.6.0 To Reproduce Ubuntu 24.10 Python 3.12.7 pip install \ mcp=...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/611
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"401 Unauthorized","articleBody":"**Describe the bug**\n\nConnecting from OpenAI SDK gives `401 Unauthorized`, pretty sure https://github.com/modelcontextprotocol/python-sdk/pull/255 is related from 1.7.0 release. This worked with `1.6.0`\n\n**To Reproduce**\n\n- Ubuntu 24.10\n- Python 3.12.7\n\n```bash\npip install \\\n mcp==1.7.0 \\\n openai==1.76.2 \\\n openai-agents==0.0.14\n```\n\n\n**openai_agent_mcp.py**\n\n```python\nimport asyncio\n\nimport agents.mcp as openai_agents_mcp\nfrom agents import Agent, Runner\n\n\nasync def main():\n async with openai_agents_mcp.MCPServerSse(\n name=\"files\",\n params={\n \"url\": f\"http://localhost:8000/sse\",\n },\n ) as mcp_server:\n\n agent = Agent(\n name=\"Assistant\",\n instructions=\"Use the tools to read the filesystem and answer questions based on those files.\",\n mcp_servers=[mcp_server],\n )\n\n # List the files it can read\n message = \"Read the os-release file and tell us what OS we are on\"\n print(f\"Running: {message}\")\n result = await Runner.run(starting_agent=agent, input=message)\n print(result.final_output)\n\nif __name__ == \"__main__\":\n asyncio.run(main())\n\n```\n\n**mcp_server_files.py**\n\n```python\nimport sys\nimport click\nimport pathlib\n\nimport uvicorn\nfrom mcp.server.fastmcp import FastMCP\n\nimport logging\n\nlogging.basicConfig(level=logging.DEBUG)\n\n\nos_release_path = pathlib.Path(\"/usr/lib/os-release\")\nif not os_release_path.exists():\n os_release_path = pathlib.Path(\"/etc/os-release\")\nif not os_release_path.exists():\n os_release_path = pathlib.Path(__file__)\n\n\nSAMPLE_RESOURCES = {\n \"/usr/lib/os-release\": os_release_path.read_text(),\n \"/etc/os-release\": os_release_path.read_text(),\n}\n\n\n@click.command()\n@click.option(\"--port\", default=8000, help=\"Port to listen on for SSE\")\n@click.option(\n \"--transport\",\n type=click.Choice([\"stdio\", \"sse\"]),\n default=\"stdio\",\n help=\"Transport type\",\n)\ndef main(port: int, transport: str) -\u003e int:\n # Create server\n mcp = FastMCP(\"OS info sever\")\n\n\n @mcp.tool()\n def get_files() -\u003e list[str]:\n print(\"[debug-server] get_files()\")\n return list(SAMPLE_RESOURCES.keys())\n\n\n @mcp.tool()\n def get_file_content(file: str) -\u003e str:\n print(\"[debug-server] get_file_content()\")\n return SAMPLE_RESOURCES[file]\n\n\n mcp.run(transport=\"sse\")\n\nif __name__ == \"__main__\":\n sys.exit(main())\n```\n\n**Expected behavior**\n\n```\nDEBUG:mcp.server.sse:Setting up SSE connection\nDEBUG:mcp.server.sse:Created new session with ID: 4c94bb47-1858-45f1-8f07-9a2cc31ae840\nDEBUG:mcp.server.sse:Starting SSE response task\nDEBUG:mcp.server.sse:Yielding read and write streams\nINFO: 127.0.0.1:62467 - \"GET /sse HTTP/1.1\" 200 OK\n```\n\n**Screenshots**\n\n```\nDEBUG:mcp.server.lowlevel.server:Registering handler for ListToolsRequest\nDEBUG:mcp.server.lowlevel.server:Registering handler for CallToolRequest\nDEBUG:mcp.server.lowlevel.server:Registering handler for ListResourcesRequest\nDEBUG:mcp.server.lowlevel.server:Registering handler for ReadResourceRequest\nDEBUG:mcp.server.lowlevel.server:Registering handler for PromptListRequest\nDEBUG:mcp.server.lowlevel.server:Registering handler for GetPromptRequest\nDEBUG:mcp.server.lowlevel.server:Registering handler for ListResourceTemplatesRequest\nDEBUG:asyncio:Using selector: KqueueSelector\nDEBUG:mcp.server.sse:SseServerTransport initialized with endpoint: /messages/\nINFO: Started server process [60590]\nINFO: Waiting for application startup.\nINFO: Application startup complete.\nINFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)\nINFO: 127.0.0.1:62493 - \"GET /sse HTTP/1.1\" 401 Unauthorized\n```\n\n```\nError initializing MCP server: unhandled errors in a TaskGroup (1 sub-exception)\n + Exception Group Traceback (most recent call last):\n | File \"/home/johnandersen777/sshai-client/openai_agent_mcp.py\", line 26, in \u003cmodule\u003e\n | asyncio.run(main())\n | File \"/usr/lib/python3.12/asyncio/runners.py\", line 194, in run\n | return runner.run(main)\n | ^^^^^^^^^^^^^^^^\n | File \"/usr/lib/python3.12/asyncio/runners.py\", line 118, in run\n | return self._loop.run_until_complete(task)\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n | File \"/usr/lib/python3.12/asyncio/base_events.py\", line 687, in run_until_complete\n | return future.result()\n | ^^^^^^^^^^^^^^^\n | File \"/home/johnandersen777/sshai-client/openai_agent_mcp.py\", line 6, in main\n | async with openai_agents_mcp.MCPServerSse(\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n | File \"/home/johnandersen777/.local/.venv/lib/python3.12/site-packages/agents/mcp/server.py\", line 94, in __aenter__\n | await self.connect()\n | File \"/home/johnandersen777/.local/.venv/lib/python3.12/site-packages/agents/mcp/server.py\", line 107, in connect\n | transport = await self.exit_stack.enter_async_context(self.create_streams())\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n | File \"/usr/lib/python3.12/contextlib.py\", line 659, in enter_async_context\n | result = await _enter(cm)\n | ^^^^^^^^^^^^^^^^\n | File \"/usr/lib/python3.12/contextlib.py\", line 210, in __aenter__\n | return await anext(self.gen)\n | ^^^^^^^^^^^^^^^^^^^^^\n | File \"/home/johnandersen777/.local/.venv/lib/python3.12/site-packages/mcp/client/sse.py\", line 43, in sse_client\n | async with anyio.create_task_group() as tg:\n | ^^^^^^^^^^^^^^^^^^^^^^^^^\n | File \"/home/johnandersen777/.local/.venv/lib/python3.12/site-packages/anyio/_backends/_asyncio.py\", line 772, in __aexit__\n | raise BaseExceptionGroup(\n | ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)\n +-+---------------- 1 ----------------\n | Traceback (most recent call last):\n | File \"/home/johnandersen777/.local/.venv/lib/python3.12/site-packages/mcp/client/sse.py\", line 53, in sse_client\n | event_source.response.raise_for_status()\n | File \"/home/johnandersen777/.local/.venv/lib/python3.12/site-packages/httpx/_models.py\", line 829, in raise_for_status\n | raise HTTPStatusError(message, request=request, response=self)\n | httpx.HTTPStatusError: Client error '401 Unauthorized' for url 'http://localhost:8000/sse'\nFor more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/401\n```\n","author":{"url":"https://github.com/johnandersen777","@type":"Person","name":"johnandersen777"},"datePublished":"2025-05-01T20:24:15.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/611/python-sdk/issues/611"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:691c4af6-0d45-40ed-a497-7cb2e808d672 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A930:19A853:11E3A5D:17F7FA0:6A5AAC8C |
| html-safe-nonce | 6edb683f1f0919fa9eaba8f510e2d07df0cd8dd8b77a75493c4eec8a839804de |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBOTMwOjE5QTg1MzoxMUUzQTVEOjE3RjdGQTA6NkE1QUFDOEMiLCJ2aXNpdG9yX2lkIjoiNTUzNjIyNDA5NDg0NzY3NTUzMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | a4ce6d7c4495a9c2f4463ab65ec799dca5bc6210177857623066b80d07cf7fce |
| hovercard-subject-tag | issue:3034646875 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/modelcontextprotocol/python-sdk/611/issue_layout |
| twitter:image | https://opengraph.githubassets.com/81db936f63169eb3b1a806a07a8003e13d6554a4d5b2efe2d2b865a55d59c933/modelcontextprotocol/python-sdk/issues/611 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/81db936f63169eb3b1a806a07a8003e13d6554a4d5b2efe2d2b865a55d59c933/modelcontextprotocol/python-sdk/issues/611 |
| og:image:alt | Describe the bug Connecting from OpenAI SDK gives 401 Unauthorized, pretty sure #255 is related from 1.7.0 release. This worked with 1.6.0 To Reproduce Ubuntu 24.10 Python 3.12.7 pip install \ mcp=... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | johnandersen777 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 21c53da6db0c40484841ba32fe19ecf485e7e734334faab487cd59d884d2bb33 |
| turbo-cache-control | no-preview |
| go-import | github.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git |
| octolytics-dimension-user_id | 182288589 |
| octolytics-dimension-user_login | modelcontextprotocol |
| octolytics-dimension-repository_id | 862584018 |
| octolytics-dimension-repository_nwo | modelcontextprotocol/python-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 862584018 |
| octolytics-dimension-repository_network_root_nwo | modelcontextprotocol/python-sdk |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 6e85f20f54e1147d8162094880590864abefff6b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width