xTaskjs 1.0 ya está disponible: cuentas por rol, documentación y una interfaz personalizable.

Paquetes

@xtaskjs/mcp

Decorator-based MCP server builder, lifecycle hooks, and SDK transport adapters.

npm install @xtaskjs/mcp reflect-metadata @modelcontextprotocol/sdk Ruta del paquete: packages/mcp

Resumen

Qué controla este paquete en el runtime

MCP adds a decorator-driven server builder for Model Context Protocol servers. It registers tools, prompts, resources, and lifecycle hooks inside the xtaskjs runtime, and it can bridge the official @modelcontextprotocol/sdk transports for stdio or Streamable HTTP.

Qué ofrece

  • McpServer(), McpTool(), McpPrompt(), and McpResource() declare server capabilities with DI-friendly classes.
  • OnMcpServerStart() and OnMcpServerStop() hook server lifecycle into application startup and shutdown.
  • InjectMcpService() and InjectMcpLifecycleManager() expose the runtime through DI-managed services.
  • createMcpSdkServerAdapter(), connectMcpSdkStdio(), and bindMcpSdkStreamableHttp() integrate with official MCP SDK transports.

Cómo encaja

  • Pairs with @xtaskjs/core so the MCP runtime initializes and shuts down alongside the rest of the application.
  • Useful when an app needs to expose tools, prompts, resources, or authenticated endpoints over /mcp.
  • Demonstrated by the 28-mcp_server_app and 29-mcp_auth_http_app samples.

Mapa de uso

Qué peso tiene este paquete dentro del runtime

Arranque

4/5

Inyección de dependencias

5/5

Tools / Prompts

5/5

Lifecycle Hooks

5/5

SDK Transport

4/5

Flujo del paquete

Cómo atraviesa este paquete las fases del runtime de xtaskjs

Antes del arranque

Import reflect-metadata, declare your MCP server class, and define tools, prompts, resources, or lifecycle hooks before application bootstrap.

Durante CreateApplication()

MCP integration registers the server with the xtaskjs container so the runtime can expose methods and lifecycle hooks when the application starts.

During transport binding

Use the official SDK adapters to connect stdio or Streamable HTTP transports, or protect the HTTP endpoint with security middleware.

Superficie API

Exports representativos del paquete original

Server decorators

  • McpServer
  • McpTool
  • McpPrompt
  • McpResource

Lifecycle and runtime

  • McpService
  • InjectMcpService
  • InjectMcpLifecycleManager
  • OnMcpServerStart
  • OnMcpServerStop
  • getMcpServiceToken
  • getMcpLifecycleToken

Lifecycle and SDK adapters

  • initializeMcpIntegration
  • shutdownMcpIntegration
  • resetMcpIntegration
  • createMcpSdkServerAdapter
  • connectMcpSdkStdio
  • bindMcpSdkStreamableHttp

Uso

Flujo típico de adopción

1. Declare servers and handlers

Use McpServer, McpTool, McpPrompt, and McpResource on DI-managed classes to expose protocol capabilities.

2. Hook startup and shutdown

Apply OnMcpServerStart and OnMcpServerStop for initialization work, health checks, or graceful teardown.

3. Bind a transport

Connect the server through stdio or Streamable HTTP with the official MCP SDK helpers when you are ready to expose it externally.

Ejemplo

Fragmento de referencia

Declare an MCP server with tools and hooks
import { Service } from "@xtaskjs/core";
import { McpPrompt, McpServer, McpTool, OnMcpServerStart, OnMcpServerStop } from "@xtaskjs/mcp";

@Service()
@McpServer({
  name: "docs-mcp",
  version: "1.0.0",
  instructions: "Expose documentation helpers over MCP",
  group: ["docs", "mcp"],
})
export class DocsMcpServer {
  @OnMcpServerStart()
  onStart() {}

  @OnMcpServerStop()
  onStop() {}

  @McpTool("search-docs", { description: "Search docs" })
  searchDocs(payload: { query: string }) {
    return { query: payload.query };
  }

  @McpPrompt("welcome", { description: "Generate a docs welcome prompt" })
  welcome(input?: { name?: string }) {
    return `Welcome ${input?.name || "world"}`;
  }
}

Ejemplos

Ejemplos oficiales para revisar después

Ejemplos de referencia: 28-mcp_server_app and 29-mcp_auth_http_app