Skip to content

Commit dd59651

Browse files
committed
improve mcp
1 parent 4ded641 commit dd59651

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

app/routes/mcp+/fetch-transport.server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { randomUUID } from 'node:crypto'
1+
// maybe this'll get built-into the SDK: https://github.com/modelcontextprotocol/typescript-sdk/issues/260
22
import { type Transport } from '@modelcontextprotocol/sdk/shared/transport.js'
33
import {
44
type JSONRPCMessage,
@@ -24,7 +24,7 @@ export class FetchSSEServerTransport implements Transport {
2424
*/
2525
constructor(endpoint: string, sessionId?: string | null) {
2626
this.#endpoint = endpoint
27-
this.#sessionId = sessionId ?? randomUUID()
27+
this.#sessionId = sessionId ?? crypto.randomUUID()
2828
}
2929

3030
/**

app/routes/mcp+/index.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { invariantResponse } from '@epic-web/invariant'
12
import { type Route } from './+types/index.ts'
23
import { connect, getTransport } from './mcp.server.ts'
34

@@ -11,12 +12,10 @@ export async function loader({ request }: Route.LoaderArgs) {
1112
export async function action({ request }: Route.ActionArgs) {
1213
const url = new URL(request.url)
1314
const sessionId = url.searchParams.get('sessionId')
14-
if (!sessionId) {
15-
return new Response('No session ID', { status: 400 })
16-
}
15+
invariantResponse(sessionId, 'No session ID')
16+
1717
const transport = await getTransport(sessionId)
18-
if (!transport) {
19-
return new Response('Not found', { status: 404 })
20-
}
18+
invariantResponse(transport, 'No transport', { status: 404 })
19+
2120
return transport.handlePostMessage(request)
2221
}

app/routes/mcp+/mcp.server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const server = new McpServer(
2020

2121
server.tool(
2222
'Find User',
23+
'Search for users in the Epic Notes database by their name or username',
2324
{ query: z.string().describe('The query to search for') },
2425
async ({ query }) => {
2526
const like = `%${query ?? ''}%`

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"setup": "npm run build && prisma migrate deploy && prisma generate --sql && playwright install",
2323
"start": "cross-env NODE_ENV=production node .",
2424
"start:mocks": "cross-env NODE_ENV=production MOCKS=true tsx .",
25+
"test:mcp": "npx @modelcontextprotocol/inspector",
2526
"test": "vitest",
2627
"coverage": "vitest run --coverage",
2728
"test:e2e": "npm run test:e2e:dev --silent",

0 commit comments

Comments
 (0)