Skip to main content

Basic Examples

Get started with LeanMCP using these foundational examples demonstrating the three core MCP primitives.

Resources Example

Dynamic system configuration exposed as MCP resources.
import { Resource } from "@leanmcp/core";

export class ConfigService {
  @Resource({ 
    description: "Current server status",
    mimeType: "application/json"
  })
  serverStatus() {
    return {
      status: "healthy",
      uptime: process.uptime(),
      memory: process.memoryUsage()
    };
  }

  @Resource({ 
    description: "Feature flags configuration",
    mimeType: "application/json"
  })
  featureFlags() {
    return {
      darkMode: true,
      betaFeatures: false,
      maxUploadSize: "10MB"
    };
  }
}

View Full Example

System Config Resource Example

Prompts Example

Customer support assistant with specialized prompts.
import { Prompt } from "@leanmcp/core";

export class AssistantService {
  @Prompt({ description: "Customer support conversation" })
  customerSupport(input: { customerName: string; issue: string }) {
    return {
      messages: [{
        role: "user",
        content: {
          type: "text",
          text: `You are a helpful customer support agent.
          
Customer: ${input.customerName}
Issue: ${input.issue}

Respond professionally and helpfully.`
        }
      }]
    };
  }

  @Prompt({ description: "Code review assistant" })
  codeReviewer() {
    return {
      messages: [
        {
          role: "user",
          content: { type: "text", text: "You are a senior code reviewer." }
        },
        {
          role: "assistant",
          content: { type: "text", text: "I'll review for bugs, style, and best practices." }
        }
      ]
    };
  }
}

View Full Example

Customer Assistant Prompts Example

Run the Examples

# Clone the repository
git clone https://github.com/Leanmcp-Community/sdk-examples.git
cd sdk-examples

# Run resources example
cd core-examples/resources-example/system-config-resource
npm install && npm run dev

# Run prompts example
cd core-examples/prompts-example/customer-assistant
npm install && npm run dev

Next Steps