Skip to main content

Decorator Categories

Server Decorators

  • @FrontMcp - Bootstrap MCP server
  • @App - Define application modules

Entry Decorators

  • @Tool - Define MCP tools
  • @Resource / @ResourceTemplate - Define resources
  • @Prompt - Define prompt templates
  • @Agent - Define autonomous agents
  • @Skill - Define knowledge packages
  • @Job - Define executable jobs
  • @Workflow - Define multi-step workflows

Extension Decorators

  • @Plugin - Create plugins
  • @Provider - Dependency injection
  • @Adapter - Framework adapters

Hook Decorators

  • @Stage - Define flow stages
  • @Will - Before-stage hooks
  • @Did - After-stage hooks
  • @Around - Wrap-stage hooks

Class-Based vs Function-Based

Most entry decorators support both patterns:
import { Tool, ToolContext } from '@frontmcp/sdk';
import { z } from 'zod';

@Tool({
  name: 'get_user',
  description: 'Fetch user by ID',
  inputSchema: { userId: z.string() },
})
class GetUserTool extends ToolContext {
  async execute(input: { userId: string }) {
    const db = this.get(DatabaseToken);
    return db.findUser(input.userId);
  }
}

Function-Based (Simpler Definitions)

import { tool } from '@frontmcp/sdk';
import { z } from 'zod';

const getUserTool = tool({
  name: 'get_user',
  description: 'Fetch user by ID',
  inputSchema: { userId: z.string() },
})((input, ctx) => {
  const db = ctx.get(DatabaseToken);
  return db.findUser(input.userId);
});

Type Inference

FrontMCP provides full type inference for inputs and outputs:
import { Tool, ToolContext, ToolInputOf, ToolOutputOf } from '@frontmcp/sdk';
import { z } from 'zod';

const metadata = {
  name: 'calculate',
  inputSchema: { a: z.number(), b: z.number() },
  outputSchema: z.object({ result: z.number() }),
} as const;

// Types are inferred automatically
type Input = ToolInputOf<typeof metadata>;   // { a: number; b: number }
type Output = ToolOutputOf<typeof metadata>; // { result: number }

@Tool(metadata)
class CalculateTool extends ToolContext<
  typeof metadata.inputSchema,
  typeof metadata.outputSchema
> {
  async execute(input: Input): Promise<Output> {
    return { result: input.a + input.b };
  }
}

Common Patterns

Metadata Properties

All entry decorators share common metadata properties:
PropertyTypeDescription
namestringRequired unique identifier
descriptionstringHuman-readable description
idstringOptional stable ID for tracking
tagsstring[]Categorization tags

Context Access

All context classes provide:
// Dependency injection
const service = this.get(ServiceToken);
const optional = this.tryGet(OptionalToken);

// Scope access
const tools = this.scope.tools;

// Logging
this.logger.info('Processing request');

// Request context
const ctx = this.context;
const auth = this.getAuthInfo();

Next Steps

@FrontMcp

Bootstrap your MCP server

@Tool

Create MCP tools

@Resource

Define resources

@Prompt

Create prompt templates

@Job

Define executable jobs

@Workflow

Define multi-step workflows