|
| 1 | +# Creating a Codex fork |
| 2 | + |
| 3 | +OpenAI's Codex a is an agent designed to be your software engineering teammate. |
| 4 | + |
| 5 | +This guide will show you how to build your own version using the Agentic MCP |
| 6 | +framework. We'll create a "codex fork" agent that composes several tools to |
| 7 | +interact with your file system, terminal, and GitHub. |
| 8 | + |
| 9 | +The entire agent can be defined in a single file. This includes defining |
| 10 | +dependencies, writing the agent's documentation for the LLM, and starting the |
| 11 | +server. |
| 12 | + |
| 13 | +```typescript |
| 14 | +import { type ComposeDefinition, mcpc } from "@mcpc/core"; |
| 15 | +import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; |
| 16 | + |
| 17 | +// 1. First, Collect Your MCP Server Dependencies |
| 18 | +// Define the existing MCP servers that your agent will depend on. |
| 19 | +const deps: ComposeDefinition["deps"] = { |
| 20 | + mcpServers: { |
| 21 | + "desktop-commander": { |
| 22 | + command: "npx", |
| 23 | + args: ["-y", "@wonderwhy-er/desktop-commander@latest"], |
| 24 | + transportType: "stdio", |
| 25 | + }, |
| 26 | + "lsmcp": { |
| 27 | + command: "npx", |
| 28 | + args: ["-y", "@mizchi/lsmcp", "-p", "tsgo"], |
| 29 | + transportType: "stdio", |
| 30 | + }, |
| 31 | + "github": { |
| 32 | + transportType: "streamable-http", |
| 33 | + url: "https://api.githubcopilot.com/mcp/", |
| 34 | + headers: { |
| 35 | + // Note: You would typically use a secrets manager for API keys. |
| 36 | + "Authorization": "Bearer ${input:github_mcp_pat}", |
| 37 | + }, |
| 38 | + }, |
| 39 | + }, |
| 40 | +}; |
| 41 | + |
| 42 | +// 2. Then, Write the Documentation for Your Agent |
| 43 | +// This documentation tells the LLM what the agent does, when to use it, |
| 44 | +// and how to reference its underlying tools using the <tool> syntax. |
| 45 | +const description = ` |
| 46 | + You are a "codex fork" agent, a world-class AI assistant for coding tasks. |
| 47 | +
|
| 48 | + Your capabilities include: |
| 49 | + - Reading and writing files. |
| 50 | + - Searching the codebase using advanced language server features. |
| 51 | + - Executing terminal commands to build, test, and run projects. |
| 52 | + - Interacting with GitHub to create pull requests and manage issues. |
| 53 | +
|
| 54 | + To perform these actions, you must use the following tools: |
| 55 | + - To execute a shell command: <tool name="desktop-commander.exec" /> |
| 56 | + - To read a file's content: <tool name="desktop-commander.readFile" /> |
| 57 | + - To write content to a file: <tool name="desktop-commander.writeFile" /> |
| 58 | + - To find symbol definitions: <tool name="lsmcp.definition" /> |
| 59 | + - To create a GitHub pull request: <tool name="github.createPullRequest" /> |
| 60 | +`; |
| 61 | + |
| 62 | +// 3. Finally, Start the Agentic MCP Server |
| 63 | +// The mcpc function initializes the server and manages its tool dependencies. |
| 64 | +// We'll run it in "agentic" mode, which uses standard interactive tool calls. |
| 65 | +const server = mcpc( |
| 66 | + // Server metadata |
| 67 | + [{ |
| 68 | + name: "codex-fork-agent", |
| 69 | + version: "0.1.0", |
| 70 | + }, { |
| 71 | + capabilities: { tools: {}, sampling: {} }, |
| 72 | + }], |
| 73 | + // Agent definition |
| 74 | + [{ |
| 75 | + name: "codex-fork-agent", |
| 76 | + options: { |
| 77 | + mode: "agentic", // or "sampling" for compatible clients |
| 78 | + }, |
| 79 | + description, |
| 80 | + deps, |
| 81 | + }], |
| 82 | +); |
| 83 | + |
| 84 | +// 4. Connect to a Transport to Make the Agent Accessible |
| 85 | +// For simplicity, we connect our server to the MCP stdio transport. |
| 86 | +const transport = new StdioServerTransport(); |
| 87 | +await server.connect(transport); |
| 88 | + |
| 89 | +console.log("✅ Codex Fork agent is running and connected via stdio."); |
| 90 | +``` |
0 commit comments