@@ -109,6 +109,69 @@ export function parseMcpcConfigs(
109109 return newMcpcConfigs ;
110110}
111111
112+ /**
113+ * Create and configure an agentic MCP server with composed tools.
114+ *
115+ * This is the main entry point for building agentic MCP servers. It allows you to:
116+ * - Reuse existing MCP tools from the community by selecting and composing them
117+ * - Create powerful agentic tools by describing them in natural language with tool references
118+ * - Fine-tune tool descriptions and parameters to fit your specific use cases
119+ * - Build multi-agent systems where each agent is itself an MCP tool
120+ *
121+ * @example
122+ * ```typescript
123+ * const server = await mcpc(
124+ * [
125+ * { name: "coding-agent", version: "1.0.0" },
126+ * { capabilities: { tools: {}, sampling: {} } }
127+ * ],
128+ * [{
129+ * name: "codex-fork",
130+ * description: `A coding agent that can read files, search code, and create PRs.
131+ * Available tools:
132+ * <tool name="desktop-commander.read_file"/>
133+ * <tool name="github.create_pull_request"/>`,
134+ * deps: {
135+ * mcpServers: {
136+ * "desktop-commander": {
137+ * command: "npx",
138+ * args: ["-y", "@wonderwhy -er/desktop-commander@latest"],
139+ * transportType: "stdio"
140+ * },
141+ * "github": {
142+ * transportType: "streamable-http",
143+ * url: "https://api.githubcopilot.com/mcp/",
144+ * headers: { "Authorization": `Bearer ${process.env.GITHUB_TOKEN}` }
145+ * }
146+ * }
147+ * },
148+ * plugins: [createLargeResultPlugin({ maxSize: 8000 })],
149+ * options: { mode: "agentic", sampling: true }
150+ * }]
151+ * );
152+ * await server.connect(new StdioServerTransport());
153+ * ```
154+ *
155+ * @param serverConf - MCP server initialization parameters including name, version, and capabilities
156+ * - First element: Server metadata (name, version)
157+ * - Second element: Server capabilities (tools, sampling, etc.)
158+ *
159+ * @param composeConf - Array of agent composition definitions. Each definition includes:
160+ * - name: Agent name (set to null for composition-only mode)
161+ * - description: Agent purpose with XML-like tool references (e.g., `<tool name="server.tool"/>`)
162+ * - deps: MCP server dependencies with transport configurations (stdio, sse, streamable-http)
163+ * - plugins: Global plugins to transform/extend tool behavior (objects or file paths)
164+ * - options: Execution mode settings (agentic, agentic_workflow, sampling)
165+ *
166+ * @param setupCallback - Optional callback to register custom tools or perform additional setup
167+ * before composition. Useful for adding internal tools or custom configurations.
168+ *
169+ * @returns A configured MCP Server instance ready to connect to a transport
170+ *
171+ * @see {@link ComposeDefinition } for detailed composition configuration options
172+ * @see {@link ToolPlugin } for plugin development guide
173+ * @see https://github.com/mcpc-tech/mcpc/tree/main/docs for complete documentation
174+ */
112175export async function mcpc (
113176 serverConf : ConstructorParameters < typeof ComposableMCPServer > ,
114177 composeConf ?: ComposeDefinition [ ] ,
@@ -117,15 +180,16 @@ export async function mcpc(
117180 const server = new ComposableMCPServer ( ...serverConf ) ;
118181 const parsed = parseMcpcConfigs ( composeConf ) ;
119182
120- // Initialize built-in plugins first
183+ // Initialize built-in plugins first (e.g., large result handler, search plugin)
121184 await server . initBuiltInPlugins ( ) ;
122185
123186 // Load global plugins before composition
187+ // Plugins can transform tool descriptions, results, and behavior
124188 for ( const mcpcConfig of parsed ) {
125189 if ( mcpcConfig . plugins ) {
126190 for ( const plugin of mcpcConfig . plugins ) {
127191 if ( typeof plugin === "string" ) {
128- // Load global plugin from file
192+ // Load global plugin from file path (supports query params like ?maxSize=8000)
129193 await server . loadPluginFromPath ( plugin ) ;
130194 } else {
131195 // Register global plugin object directly
@@ -135,11 +199,18 @@ export async function mcpc(
135199 }
136200 }
137201
138- // Allow user to register tools before composing
202+ // Allow user to register custom tools or perform additional setup before composing
203+ // Useful for adding internal tools or configuring server-specific behavior
139204 if ( setupCallback ) {
140205 await setupCallback ( server ) ;
141206 }
142207
208+ // Compose each agent by connecting to MCP dependencies and creating the agentic tool
209+ // This process:
210+ // 1. Parses tool references from the description
211+ // 2. Connects to dependent MCP servers (stdio, sse, streamable-http)
212+ // 3. Selects and composes referenced tools
213+ // 4. Creates the final agentic tool with chosen execution mode
143214 for ( const mcpcConfig of parsed ) {
144215 await server . compose (
145216 mcpcConfig . name ,
0 commit comments