Skip to content

[Enhancement] Add More MCP Tool Examples #48

Description

@farce1

Enhancement Request

The current MCP server template only includes a basic "hello" tool example. Adding more comprehensive examples would help users understand MCP patterns better.

Suggested Examples to Add

1. File Handling Tool

@mcp.tool()
async def read_file(path: str) -> str:
    """Read contents of a file with proper error handling."""
    # Example implementation

2. API Integration Tool

@mcp.tool()
async def fetch_data(url: str, headers: Optional[Dict] = None) -> Dict:
    """Fetch data from an API endpoint."""
    # Example with aiohttp or httpx

3. Authentication Management

@mcp.tool()
async def verify_token(token: str) -> bool:
    """Verify authentication token."""
    # Example token validation

4. Database Operations

@mcp.tool()
async def query_database(query: str, params: Optional[List] = None) -> List[Dict]:
    """Execute database query with parameterized inputs."""
    # Example with SQLAlchemy or asyncpg

5. Data Processing

@mcp.tool()
async def process_json(data: Dict, schema: Optional[Dict] = None) -> Dict:
    """Process and validate JSON data."""
    # Example with pydantic or marshmallow

Benefits

  • Faster onboarding for new users
  • Best practices demonstration
  • Common patterns readily available
  • Reduced development time

Implementation Suggestions

  1. Create a tools/examples/ directory in the template
  2. Include well-commented example files
  3. Add a README explaining each example
  4. Include tests for each example tool

Documentation

Each example should include:

  • Clear docstrings
  • Input/output types
  • Error handling
  • Usage examples
  • Common pitfalls to avoid

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions