@@ -25,7 +25,7 @@ xsMCP v0.1 is targeted to be compatible with the `2025-03-26` revision and is no
25
25
` @xsmcp/server-http ` is based on [ Web Standards] ( https://hono.dev/docs/concepts/web-standard ) , not Express.
26
26
27
27
``` ts
28
- import { fetch } from ' @xsmcp/server-http'
28
+ import { createFetch } from ' @xsmcp/server-http'
29
29
import { createServer } from ' @xsmcp/server-shared'
30
30
import { serve } from ' srvx'
31
31
@@ -38,22 +38,19 @@ for (const tool of tools) {
38
38
}
39
39
40
40
// (req: Request) => Promise<Response>
41
- const app = fetch (server )
41
+ const fetch = createFetch (server )
42
42
43
43
// node.js, deno, bun
44
- serve ({ fetch: app })
44
+ serve ({ fetch })
45
45
46
- // next.js
47
- export const POST = app
48
-
49
- // cloudflare workers
50
- export default { fetch: app }
46
+ // cloudflare workers, pages
47
+ export default { fetch }
51
48
```
52
49
53
50
It can be used as a server on its own or with ` hono ` , ` elysia ` and ` itty-router ` for more features:
54
51
55
52
``` ts
56
- import { fetch } from ' @xsmcp/server-http'
53
+ import { createFetch } from ' @xsmcp/server-http'
57
54
import { createServer } from ' @xsmcp/server-shared'
58
55
import { Elysia } from ' elysia'
59
56
import { Hono } from ' hono'
@@ -67,19 +64,19 @@ for (const tool of tools) {
67
64
server .addTool (tool )
68
65
}
69
66
70
- const app = fetch (server )
67
+ const fetch = createFetch (server )
71
68
72
69
// hono
73
70
new Hono ()
74
- .post (' /mcp' , ({ req }) => app (req .raw ))
71
+ .post (' /mcp' , ({ req }) => fetch (req .raw ))
75
72
76
73
// elysia
77
74
new Elysia ()
78
- .post (' /mcp' , ({ request }) => app (request ))
75
+ .post (' /mcp' , ({ request }) => fetch (request ))
79
76
80
77
// itty-router
81
78
AutoRouter ()
82
- .post (' /mcp' , req => app (req ))
79
+ .post (' /mcp' , req => fetch (req ))
83
80
```
84
81
85
82
At the same time, it does not depends on any server framework thus minimizing the size.
0 commit comments