MCP Integration for AI Agents
Create an MCP App with json-render
Chapter 4 ยท MCP Integration for AI Agents
Chapter 3 wired the catalog and registry up to a browser-facing UI. This closing chapter exposes the exact same catalog and components to AI agents instead, over MCP (Model Context Protocol) โ no separate component system, no duplicated definitions.
The MCP Server
mcp/server.ts stands up an MCP server using createMCPApp from @jsonrender/mcp, communicating over stdio transport โ the standard, simple way an MCP server talks to a connecting client over standard input/output rather than a network socket.
catalog object Chapter 2 built for the browser-facing pipeline โ there's no separate, parallel definition of what components exist for the "AI agent" side of the app.
What Agents Can See
Once running, the MCP server exposes real, structured information an agent can query and act on:
- The full component list โ every entry in the catalog, so an agent knows what it's allowed to reference
- Initial state โ a starting point for whatever the agent is being asked to build or modify
- Available specs โ existing, named specs (like
dashboard) the agent can inspect or extend, rather than starting from nothing
Testing With the MCP Inspector
The real, standard way to test an MCP server directly โ without needing a full agent client wired up yet โ is the MCP Inspector:
Running this connects to the local MCP server and lets you browse its exposed tools directly โ the same real catalog, initial state, and specs an actual AI agent would see, inspectable by hand before ever connecting a real agent to it.
The Core Value: Define Once, Render Anywhere
| Browser path (Ch. 3) | Agent path (Ch. 4) | |
|---|---|---|
| Entry point | app/api/generate/route.ts | mcp/server.ts |
| Consumer | A human, via the Dashboard Builder UI | An AI agent, over MCP |
| Shared source | The same catalog, registry, and specs | |
Hands-On Exercises
A new component is added to the catalog and given a real registry entry, but only the browser-facing dashboard picks it up โ an AI agent connecting via MCP still doesn't see it. Explain, in your own words, the most likely cause, based on this chapter's own "same catalog" material.
๐ View solutionExplain, in your own words, why testing with the MCP Inspector before connecting a real AI agent is a genuinely useful step, rather than an unnecessary extra one.
๐ View solutionSummarize, in your own words, how each of this course's four chapters contributed to the final "define once, render anywhere" result โ one sentence per chapter.
๐ View solutionCourse Complete
- mcp/server.ts:
createMCPAppfrom@jsonrender/mcp, stdio transport, reusing the exact same catalog and specs as the browser path - Agents see the real component list, initial state, and available specs
- Test with
npx @modelcontextprotocol/inspectorbefore connecting a real agent - The course's own core value: define components once, render anywhere โ a human in a browser (Ch.3) and an AI agent over MCP (Ch.4) both draw from the identical catalog, registry, and specs built in Chapter 2
- Create an MCP App with json-render is now complete โ 4/4 chapters.