mirror of
https://github.com/jjbrunton/Sauci.git
synced 2026-10-31 18:19:43 +00:00
Use StreamableHTTP transport for MCP server
This commit is contained in:
1 parent
98621ca3fa
commit
2e05105bb0
2 files changed
+10
-10
No files matched your search
@@ -8,19 +8,15 @@ const app = new Hono();
|
|||||||
|
|
||||||
app.use('*', logger());
|
app.use('*', logger());
|
||||||
app.use('/mcp', authMiddleware);
|
app.use('/mcp', authMiddleware);
|
||||||
|
app.use('/mcp/*', authMiddleware);
|
||||||
|
|
||||||
app.get('/health', (c) => c.json({ status: 'ok', service: 'sauci-mcp' }));
|
app.get('/health', (c) => c.json({ status: 'ok', service: 'sauci-mcp' }));
|
||||||
|
|
||||||
// Initialize MCP server
|
// Initialize MCP server with StreamableHTTP transport
|
||||||
const mcpServer = createMcpServer();
|
const mcpServer = createMcpServer();
|
||||||
|
|
||||||
// Mount MCP server
|
// StreamableHTTP endpoint - handles all MCP communication
|
||||||
app.all('/mcp', async (c) => {
|
app.all('/mcp', async (c) => {
|
||||||
// Add headers to prevent Nginx/proxy buffering for SSE
|
|
||||||
c.header('X-Accel-Buffering', 'no');
|
|
||||||
c.header('Cache-Control', 'no-cache');
|
|
||||||
c.header('Connection', 'keep-alive');
|
|
||||||
|
|
||||||
return mcpServer.handleRequest(c);
|
return mcpServer.handleRequest(c);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -11,11 +11,15 @@ export const authMiddleware = async (c: Context, next: Next) => {
|
|||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!authHeader || !authHeader.startsWith('Bearer ')) {
|
let token = c.req.header('Authorization')?.replace('Bearer ', '');
|
||||||
return c.json({ error: 'Unauthorized: Missing or invalid Authorization header' }, 401);
|
|
||||||
|
if (!token) {
|
||||||
|
token = c.req.query('apiKey');
|
||||||
}
|
}
|
||||||
|
|
||||||
const token = authHeader.replace('Bearer ', '');
|
if (!token) {
|
||||||
|
return c.json({ error: 'Unauthorized: Missing or invalid Authorization header or apiKey query param' }, 401);
|
||||||
|
}
|
||||||
|
|
||||||
if (token !== apiKey) {
|
if (token !== apiKey) {
|
||||||
return c.json({ error: 'Unauthorized: Invalid API key' }, 401);
|
return c.json({ error: 'Unauthorized: Invalid API key' }, 401);
|
||||||
|
|||||||
Reference in new issue
Block a user