MCP Server returns 405 when adding MCP Tool URL #20532

Closed
opened 2026-02-21 20:07:51 -05:00 by yindo · 2 comments
Owner

Originally created by @shamspias on GitHub (Nov 25, 2025).

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.10.0

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

  1. In Dify Studio, create a new blank Chatflow.
  2. Save and publish it (example name: test).
  3. Enable MCP and copy the generated MCP server URL.
  4. Go to Tools → MCP.
  5. Add a new MCP tool using the Chatflow-generated URL.
  6. After saving, Dify shows the following error:
Failed to connect to MCP server:
code=405
message="Client error '405 Method Not Allowed' for url 'http://domain/mcp/server/XgKJ5PqGlR5gfLJ0/mcp'"

✔️ Expected Behavior

Dify should successfully connect to the Chatflow’s MCP server URL and register the MCP tool without errors.

Actual Behavior

A 405 Method Not Allowed error appears immediately after adding the MCP tool.
The MCP endpoint cannot be reached by the Tools section even though it was generated by Dify itself.

Image
Originally created by @shamspias on GitHub (Nov 25, 2025). ### Self Checks - [x] I have read the [Contributing Guide](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) and [Language Policy](https://github.com/langgenius/dify/issues/1542). - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report, otherwise it will be closed. - [x] 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 1.10.0 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce 1. In **Dify Studio**, create a new blank Chatflow. 2. Save and publish it (example name: `test`). 3. Enable **MCP** and copy the generated MCP server URL. 4. Go to **Tools → MCP**. 5. Add a new MCP tool using the Chatflow-generated URL. 6. After saving, Dify shows the following error: ``` Failed to connect to MCP server: code=405 message="Client error '405 Method Not Allowed' for url 'http://domain/mcp/server/XgKJ5PqGlR5gfLJ0/mcp'" ``` ### ✔️ Expected Behavior Dify should successfully connect to the Chatflow’s MCP server URL and register the MCP tool without errors. ### ❌ Actual Behavior A **405 Method Not Allowed** error appears immediately after adding the MCP tool. The MCP endpoint cannot be reached by the Tools section even though it was generated by Dify itself. <img width="2034" height="820" alt="Image" src="https://github.com/user-attachments/assets/0d6f564a-8d69-4b19-b66f-8da2af34854e" />
yindo added the 🐞 bug label 2026-02-21 20:07:51 -05:00
yindo closed this issue 2026-02-21 20:07:51 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Nov 25, 2025):

The 405 error happens because the MCP server endpoint only supports POST requests—any GET or OPTIONS request (like a browser preflight) will return 405 by design. This is common if the MCP server URL is accessed with the wrong HTTP method or if there’s a CORS/preflight issue in a self-hosted Docker setup. The MCP endpoint does not have CORS enabled by default, so cross-origin requests may fail if an OPTIONS preflight is sent and not handled, resulting in a 405 error instead of a successful registration. source source

To fix this:

  • Double-check that the MCP server_url you use in Tools matches exactly (including path and trailing slash) the one generated by the Chatflow. Even a small mismatch can cause a 405 error source.
  • If you’re running in Docker, make sure you use Docker-internal hostnames (like http://nginx:80/mcp/server/<id>/mcp) or host.docker.internal instead of your host IP, since containers can’t always reach the host IP directly source.
  • If you’re accessing the MCP endpoint from a browser or another origin, you may need to add CORS support to the MCP blueprint in Flask to allow OPTIONS and POST methods. Without this, preflight requests will fail with 405.
  • If the error persists, capture the request logs (method, URL, headers) for both working and failing scenarios to spot any differences.

If you want to add CORS to the MCP blueprint, you can do so in your Flask app setup:

from flask_cors import CORS
CORS(mcp_bp, methods=["POST", "OPTIONS"])

After making changes, clear your Nginx cache and restart your Docker containers to ensure the new settings take effect source.

Let me know if you need help with the CORS config or want to share your request logs for further troubleshooting.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

@dosubot[bot] commented on GitHub (Nov 25, 2025): <!-- Answer --> The 405 error happens because the MCP server endpoint only supports POST requests—any GET or OPTIONS request (like a browser preflight) will return 405 by design. This is common if the MCP server URL is accessed with the wrong HTTP method or if there’s a CORS/preflight issue in a self-hosted Docker setup. The MCP endpoint does not have CORS enabled by default, so cross-origin requests may fail if an OPTIONS preflight is sent and not handled, resulting in a 405 error instead of a successful registration. [source](https://github.com/langgenius/dify/blob/82dac2eba06a303154d7cd390a854a8a0b48b1bc/api/controllers/mcp/mcp.py#L36-L146) [source](https://github.com/langgenius/dify/blob/82dac2eba06a303154d7cd390a854a8a0b48b1bc/api/extensions/ext_blueprints.py#L19-L67) To fix this: - Double-check that the MCP server_url you use in Tools matches exactly (including path and trailing slash) the one generated by the Chatflow. Even a small mismatch can cause a 405 error [source](https://github.com/langgenius/dify/issues/22841#issuecomment-3106833004). - If you’re running in Docker, make sure you use Docker-internal hostnames (like `http://nginx:80/mcp/server/<id>/mcp`) or `host.docker.internal` instead of your host IP, since containers can’t always reach the host IP directly [source](https://github.com/langgenius/dify/issues/25068). - If you’re accessing the MCP endpoint from a browser or another origin, you may need to add CORS support to the MCP blueprint in Flask to allow OPTIONS and POST methods. Without this, preflight requests will fail with 405. - If the error persists, capture the request logs (method, URL, headers) for both working and failing scenarios to spot any differences. If you want to add CORS to the MCP blueprint, you can do so in your Flask app setup: ```python from flask_cors import CORS CORS(mcp_bp, methods=["POST", "OPTIONS"]) ``` After making changes, clear your Nginx cache and restart your Docker containers to ensure the new settings take effect [source](https://github.com/langgenius/dify/discussions/28076). Let me know if you need help with the CORS config or want to share your request logs for further troubleshooting. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/44c0cdbb-a3ba-498f-b0f9-77a713fab4cb?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/44c0cdbb-a3ba-498f-b0f9-77a713fab4cb?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/44c0cdbb-a3ba-498f-b0f9-77a713fab4cb?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/44c0cdbb-a3ba-498f-b0f9-77a713fab4cb?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/44c0cdbb-a3ba-498f-b0f9-77a713fab4cb?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/44c0cdbb-a3ba-498f-b0f9-77a713fab4cb?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/44c0cdbb-a3ba-498f-b0f9-77a713fab4cb?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/6088a4f4-073a-43f3-b3d4-4f06fb0c05a0/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=The%20405%20error%20happens%20because%20the%20MCP%20server%20endpoint%20only%20supports%20POST%20requests%E2%80%94any%20GET%20or%20OPTIONS%20request%20%28like%20a%20browser%20preflight%29%20will%20return%20405%20by%20design.%20This%20is%20common%20if%20the%20MCP%20server%20URL%20is%20accessed%20with%20the%20wrong%20HTTP%20method%20or%20if%20there%E2%80%99s%20a%20CORS/preflight%20issue%20in%20a%20self-hosted%20Docker%20setup.%20The%20MCP%20endpoint%20does%20not%20have%20CORS%20enabled%20by%20default%2C%20so%20cross-origin%20requests%20may%20fail%20if%20an%20OPTIONS%20preflight%20is%20sent%20and%20not%20handled%2C%20resulting%20in%20a%20405%20error%20instead%20of%20a%20successful%20registration.%20%5Bsource%5D%28https%3A//github.com/langgenius/dify/blob/82dac2eba06a303154d7cd390a854a8a0b48b1bc/api/controllers/mcp/mcp.py%23L36-L146%29%20%5Bsource%5D%28https%3A//github.com/langgenius/dify/blob/82dac2eba06a303154d7cd390a854a8a0b48b1bc/api/extensions/ext_blueprints.py%23L19-L67%29%0A%0ATo%20fix%20this%3A%0A-%20Double-check%20that%20the%20MCP%20server_url%20you%20use%20in%20Tools%20matches%20exactly%20%28including%20path%20and%20trailing%20slash%29%20the%20one%20generated%20by%20the%20Chatflow.%20Even%20a%20small%20mismatch%20can%20cause%20a%20405%20error%20%5Bsource%5D%28https%3A//github.com/langgenius/dify/issues/22841%23issuecomment-3106833004%29.%0A-%20If%20you%E2%80%99re%20running%20in%20Docker%2C%20make%20sure%20you%20use%20Docker-internal%20hostnames%20%28like%20%60http%3A//nginx%3A80/mcp/server/%3Cid%3E/mcp%60%29%20or%20%60host.docker.internal%60%20instead%20of%20your%20host%20IP%2C%20since%20containers%20can%E2%80%99t%20always%20reach%20the%20host%20IP%20directly%20%5Bsource%5D%28https%3A//github.com/langgenius/dify/issues/25068%29.%0A-%20If%20you%E2%80%99re%20accessing%20the%20MCP%20endpoint%20from%20a%20browser%20or%20another%20origin%2C%20you%20may%20need%20to%20add%20CORS%20support%20to%20the%20MCP%20blueprint%20in%20Flask%20to%20allow%20OPTIONS%20and%20POST%20methods.%20Without%20this%2C%20preflight%20requests%20will%20fail%20with%20405.%0A-%20If%20the%20error%20persists%2C%20capture%20the%20request%20logs%20%28method%2C%20URL%2C%20headers%29%20for%20both%20working%20and%20failing%20scenarios%20to%20spot%20any%20differences.%0A%0AIf%20you%20want%20to%20add%20CORS%20to%20the%20MCP%20blueprint%2C%20you%20can%20do%20so%20in%20your%20Flask%20app%20setup%3A%0A%0A%60%60%60python%0Afrom%20flask_cors%20import%20CORS%0ACORS%28mcp_bp%2C%20methods%3D%5B%22POST%22%2C%20%22OPTIONS%22%5D%29%0A%60%60%60%0A%0AAfter%20making%20changes%2C%20clear%20your%20Nginx%20cache%20and%20restart%20your%20Docker%20containers%20to%20ensure%20the%20new%20settings%20take%20effect%20%5Bsource%5D%28https%3A//github.com/langgenius/dify/discussions/28076%29.%0A%0ALet%20me%20know%20if%20you%20need%20help%20with%20the%20CORS%20config%20or%20want%20to%20share%20your%20request%20logs%20for%20further%20troubleshooting.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify/issues/28632)
Author
Owner

@shamspias commented on GitHub (Nov 25, 2025):

It didn’t work because the MCP URL was provided without HTTPS. It starts after SSL is done, so after I changed it from HTTP to HTTPS, everything worked.

@shamspias commented on GitHub (Nov 25, 2025): It didn’t work because the MCP URL was provided without HTTPS. It starts after SSL is done, so after I changed it from HTTP to HTTPS, everything worked.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#20532