|
1 |
| -<div align="center"> |
2 |
| - <h1 align="center"><a href="https://www.epicweb.dev/epic-stack">The Epic Stack 🚀</a></h1> |
3 |
| - <strong align="center"> |
4 |
| - Ditch analysis paralysis and start shipping Epic Web apps. |
5 |
| - </strong> |
6 |
| - <p> |
7 |
| - This is an opinionated project starter and reference that allows teams to |
8 |
| - ship their ideas to production faster and on a more stable foundation based |
9 |
| - on the experience of <a href="https://kentcdodds.com">Kent C. Dodds</a> and |
10 |
| - <a href="https://github.com/epicweb-dev/epic-stack/graphs/contributors">contributors</a>. |
11 |
| - </p> |
12 |
| -</div> |
13 |
| - |
14 |
| -```sh |
15 |
| -npx create-epic-app@latest |
| 1 | +# Epic MCP |
| 2 | + |
| 3 | +An [Epic Stack](https://github.com/epicweb-dev/epic-stack) example adding |
| 4 | +support for the Model Context Protocol (MCP). |
| 5 | + |
| 6 | +## What is MCP? |
| 7 | + |
| 8 | +The Model Context Protocol (MCP) is an open protocol that standardizes how |
| 9 | +applications provide context to Large Language Models (LLMs). Think of MCP like |
| 10 | +a USB-C port for AI applications - it provides a standardized way to connect AI |
| 11 | +models to different data sources and tools. |
| 12 | + |
| 13 | +Learn more from the |
| 14 | +[MCP Documentation](https://modelcontextprotocol.io/introduction) |
| 15 | + |
| 16 | +## Example Implementation |
| 17 | + |
| 18 | +This repository demonstrates how to integrate MCP into an Epic Stack |
| 19 | +application. The implementation includes: |
| 20 | + |
| 21 | +1. Server-side MCP setup for handling client connections |
| 22 | +2. SSE (Server-Sent Events) transport layer for real-time communication |
| 23 | +3. Example tool implementations showing how to expose functionality to LLMs |
| 24 | + |
| 25 | +### Key Components |
| 26 | + |
| 27 | +#### 1. MCP Server Setup (`app/routes/mcp+/mcp.server.ts`) |
| 28 | + |
| 29 | +```ts |
| 30 | +export const server = new McpServer( |
| 31 | + { |
| 32 | + name: 'epic-mcp-a25d', |
| 33 | + version: '1.0.0', |
| 34 | + }, |
| 35 | + { |
| 36 | + capabilities: { |
| 37 | + tools: {}, |
| 38 | + }, |
| 39 | + }, |
| 40 | +) |
| 41 | +``` |
| 42 | + |
| 43 | +The MCP server is the core component that handles tool registration and |
| 44 | +execution. It's configured with a unique name and version, and defines the |
| 45 | +capabilities it provides. |
| 46 | + |
| 47 | +#### 2. Tool Implementation |
| 48 | + |
| 49 | +```ts |
| 50 | +server.tool( |
| 51 | + 'Find User', |
| 52 | + 'Search for users in the Epic Notes database by their name or username', |
| 53 | + { query: z.string().describe('The query to search for') }, |
| 54 | + async ({ query }) => { |
| 55 | + // Implementation... |
| 56 | + }, |
| 57 | +) |
16 | 58 | ```
|
17 | 59 |
|
18 |
| -[](https://www.epicweb.dev/epic-stack) |
| 60 | +Tools are the primary way to expose functionality to LLMs. Each tool: |
19 | 61 |
|
20 |
| -[The Epic Stack](https://www.epicweb.dev/epic-stack) |
| 62 | +- Has a descriptive name and purpose |
| 63 | +- Uses Zod for type-safe parameter validation |
| 64 | +- Can return multiple content types (text, images, etc.) |
| 65 | +- Integrates with your existing application logic |
21 | 66 |
|
22 |
| -<hr /> |
| 67 | +#### 3. Transport Layer (`app/routes/mcp+/fetch-transport.server.ts`) |
23 | 68 |
|
24 |
| -## Watch Kent's Introduction to The Epic Stack |
| 69 | +The transport layer handles the bi-directional communication between the MCP |
| 70 | +client and server: |
| 71 | + |
| 72 | +- Uses Server-Sent Events (SSE) for real-time server-to-client communication |
| 73 | +- Handles POST requests for client-to-server messages |
| 74 | +- Maintains session state for multiple concurrent connections |
| 75 | + |
| 76 | +#### 4. Route Integration (`app/routes/mcp+/index.ts`) |
| 77 | + |
| 78 | +```ts |
| 79 | +export async function loader({ request }: Route.LoaderArgs) { |
| 80 | + const url = new URL(request.url) |
| 81 | + const sessionId = url.searchParams.get('sessionId') |
| 82 | + const transport = await connect(sessionId) |
| 83 | + return transport.handleSSERequest(request) |
| 84 | +} |
| 85 | +``` |
25 | 86 |
|
26 |
| -[](https://www.epicweb.dev/talks/the-epic-stack) |
| 87 | +The Remix route: |
27 | 88 |
|
28 |
| -["The Epic Stack" by Kent C. Dodds](https://www.epicweb.dev/talks/the-epic-stack) |
| 89 | +- Establishes SSE connections for real-time communication |
| 90 | +- Handles incoming tool requests via POST endpoints |
| 91 | +- Manages session state for multiple clients |
29 | 92 |
|
30 |
| -## Docs |
| 93 | +### Learning Points |
31 | 94 |
|
32 |
| -[Read the docs](https://github.com/epicweb-dev/epic-stack/blob/main/docs) |
33 |
| -(please 🙏). |
| 95 | +1. **Tool Design**: When designing tools for LLMs: |
34 | 96 |
|
35 |
| -## Support |
| 97 | + - Provide clear, descriptive names and purposes |
| 98 | + - Use strong type validation for parameters |
| 99 | + - Return structured responses that LLMs can understand |
| 100 | + - Consider supporting multiple content types (text, images, etc.) |
36 | 101 |
|
37 |
| -- 🆘 Join the |
38 |
| - [discussion on GitHub](https://github.com/epicweb-dev/epic-stack/discussions) |
39 |
| - and the [KCD Community on Discord](https://kcd.im/discord). |
40 |
| -- 💡 Create an |
41 |
| - [idea discussion](https://github.com/epicweb-dev/epic-stack/discussions/new?category=ideas) |
42 |
| - for suggestions. |
43 |
| -- 🐛 Open a [GitHub issue](https://github.com/epicweb-dev/epic-stack/issues) to |
44 |
| - report a bug. |
| 102 | +2. **State Management**: The implementation demonstrates: |
45 | 103 |
|
46 |
| -## Branding |
| 104 | + - Session-based connection tracking |
| 105 | + - Clean connection cleanup on client disconnect |
| 106 | + - Safe concurrent client handling |
47 | 107 |
|
48 |
| -Want to talk about the Epic Stack in a blog post or talk? Great! Here are some |
49 |
| -assets you can use in your material: |
50 |
| -[EpicWeb.dev/brand](https://epicweb.dev/brand) |
| 108 | +3. **Integration Patterns**: Learn how to: |
51 | 109 |
|
52 |
| -## Thanks |
| 110 | + - Connect MCP with existing application logic |
| 111 | + - Handle real-time communication in Remix |
| 112 | + - Structure your MCP implementation for maintainability |
53 | 113 |
|
54 |
| -You rock 🪨 |
| 114 | +4. **Security Considerations**: |
| 115 | + - Session-based access control |
| 116 | + - Safe handling of client connections |
| 117 | + - Proper cleanup of resources |
0 commit comments