-
-
Notifications
You must be signed in to change notification settings - Fork 1
fix: GET request /mcp #1
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
fix: GET request /mcp #1
Conversation
|
Name | Link |
---|---|
🔨 Latest commit | 2965e33 |
netlify/edge-functions/mcp-server.ts
Outdated
path: "/mcp", // Intercept POST /mcp | ||
method: "POST", | ||
}, | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Netlify unfortunately does not support an array for the config. To allow the static index file to be served AND redirect GET requests to /mcp
to /
we would need to do some cheeky hacks:
if (method === "GET" && pathname === "/") {
return fetch(new URL("/", req.url)); // Fetch the static asset from Netlify's CDN
}
I'm not sure if this is performant or not, maybe there is a better solution 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much cleaner solution found 2e08d68
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can just return nothing and it will respond from the origin
8329f2a
to
2e08d68
Compare
Choosing 303 as redirect status code because it indicates "see other" (when GET request happens), instead of "temp redirect" as 302 does: https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/303 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not able to check right now but I don't think this will work. The redirect will apply to POST requests too
Someone with access to the Netlify org should be able to approve the deploy requests here https://app.netlify.com/projects/docs-mcp/deploys |
This is also one of my concerns, in the Netlify docs they do not state anything about HTTP methods when using redirect, MDN just states
Which I didn't quite understood right, however Wikipedia makes it quite clear then:
I wanted to avoid having a <!doctype html><meta http-equiv="refresh" content="0;url=https://docs.astro.build/en/guides/build-with-ai/"> as this would mean Netlify has to send HTML to the client instead of redirecting directly on server-side, but maybe that's the only solution here... 🤔 |
However, I would really like to test it out in the preview, as the Netlify docs say:
https://docs.netlify.com/manage/routing/redirects/overview/#rule-processing-order |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deploy preview: https://deploy-preview-1--docs-mcp.netlify.app/
The redirect appears to be working, and POST-ing does too?
~ ❱ curl -IL https://deploy-preview-1--docs-mcp.netlify.app/mcp
HTTP/2 303
content-type: text/html; charset=UTF-8
~ ❱ curl -IL -X 'POST' https://deploy-preview-1--docs-mcp.netlify.app/mcp
HTTP/2 500
content-type: application/json
Although I’m assuming a 500 error for my empty POST is expected. Someone with an AI editor would need to test to be sure it’s working correctly.
Maybe Netlify’s static redirects like this only handle GET requests? Not sure.
Thank you very much for triggering the deployment preview! 🙌
No, that was my mistake, they handle all methods, but edge functions take precedence over redirects It's mentioned after the code block here: https://docs.netlify.com/manage/routing/redirects/overview/#rule-processing-order And after the ordered list here: https://docs.netlify.com/build/edge-functions/declarations/#declaration-processing-order |
Co-authored-by: Adam Matthiesen <[email protected]> Co-authored-by: Chris Swithinbank <[email protected]>
69367cc
to
37531e0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed the preview deploy is still working by adding it as an MCP server in VS Code. Chat sessions were able to successfully query the server and receive docs content.
Thanks @trueberryless 🙌
People (myself included) expect to see something when calling https://mcp.docs.astro.build/mcp in their browser (which is a GET request) because they initially do not understand that a MCP server works with POST requests.
I therefore added a redirect rule which redirects all HTTP methods to the Astro docs with status 303 ("See other"). But because Netlify edge functions take precedence over redirects, the MCP Server with HTTP method POST still works unaffected 🙌