mcp
This commit is contained in:
@@ -65,13 +65,15 @@ export class McpServerService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const pathname = new URL(request.url ?? '/', 'http://localhost').pathname;
|
const url = new URL(request.url ?? '/', 'http://localhost');
|
||||||
if (pathname !== '/mcp') {
|
if (!['/mcp', '/mcp/', '/api/mcp', '/api/mcp/'].includes(url.pathname)) {
|
||||||
response.writeHead(404, { 'content-type': 'application/json' });
|
response.writeHead(404, { 'content-type': 'application/json' });
|
||||||
response.end(JSON.stringify({ error: 'Not found' }));
|
response.end(JSON.stringify({ error: 'Not found' }));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
request.url = `/mcp${url.search}`;
|
||||||
|
|
||||||
if (!this.isAuthorized(request)) {
|
if (!this.isAuthorized(request)) {
|
||||||
response.writeHead(401, { 'content-type': 'application/json' });
|
response.writeHead(401, { 'content-type': 'application/json' });
|
||||||
response.end(JSON.stringify({ error: 'Unauthorized' }));
|
response.end(JSON.stringify({ error: 'Unauthorized' }));
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ server {
|
|||||||
proxy_pass http://127.0.0.1:3000;
|
proxy_pass http://127.0.0.1:3000;
|
||||||
}
|
}
|
||||||
|
|
||||||
location = /mcp {
|
location ~ ^/(api/)?mcp/?$ {
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_buffering off;
|
proxy_buffering off;
|
||||||
proxy_cache off;
|
proxy_cache off;
|
||||||
@@ -43,6 +43,7 @@ server {
|
|||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
proxy_set_header X-Forwarded-Prefix /mcp;
|
||||||
proxy_pass http://127.0.0.1:3001;
|
proxy_pass http://127.0.0.1:3001;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user