Hello World Tutorial
Related Topics: Endpoints (understand endpoint types) | Type System (parameter types) | Testing (test assertions) | Quickstart (project setup)
In this tutorial, you’ll create your first MXCP tool - a simple greeting function. You’ll learn the fundamental concepts that apply to all MXCP endpoints.
Build a tool that:
- Accepts a name parameter
- Returns a greeting message
- Can be called from the CLI and AI clients
Prerequisites
Section titled “Prerequisites”- MXCP installed (
pip install mxcp) - A terminal/command prompt
Step 1: Create a Project
Section titled “Step 1: Create a Project”Initialize a new MXCP project:
mkdir hello-mxcpcd hello-mxcpmxcp initThis creates the basic structure:
hello-mxcp/├── mxcp-site.yml├── tools/├── resources/├── prompts/├── evals/├── python/├── plugins/├── sql/├── drift/└── audit/Step 2: Create the Tool Definition
Section titled “Step 2: Create the Tool Definition”Create tools/hello.yml:
mxcp: 1tool: name: hello description: Say hello to someone enabled: true
parameters: - name: name type: string description: Name of the person to greet examples: - "World" - "Alice" - "Bob"
return: type: string description: A friendly greeting message
source: file: ../sql/hello.sqlLet’s break down each part:
| Field | Purpose |
|---|---|
mxcp: 1 | Schema version (always 1) |
name | Unique identifier for the tool |
description | What the tool does (shown to AI) |
enabled | Whether to load this tool |
parameters | Input definitions |
return | Output definition |
source | Where the implementation lives |
Step 3: Write the SQL Implementation
Section titled “Step 3: Write the SQL Implementation”Create sql/hello.sql:
SELECT 'Hello, ' || $name || '!' AS greetingThe $name syntax binds the name parameter from the tool definition. DuckDB handles the parameter substitution safely (preventing SQL injection).
Step 4: Validate Your Tool
Section titled “Step 4: Validate Your Tool”Check that your tool is correctly defined:
mxcp validateExpected output:
✓ tools/hello.yml (tool/hello)Validation complete: 1 passed, 0 failedStep 5: Run the Tool
Section titled “Step 5: Run the Tool”Execute the tool from the command line:
mxcp run tool hello --param name=WorldOutput:
greeting--------Hello, World!Try different names:
mxcp run tool hello --param name=Alicemxcp run tool hello --param name="MXCP User"Step 6: List Your Endpoints
Section titled “Step 6: List Your Endpoints”See all available endpoints:
mxcp listOutput:
Endpoints: Tools: - hello: Say hello to someone
Resources: (none)
Prompts: (none)Step 7: Add Tests
Section titled “Step 7: Add Tests”Update tools/hello.yml to include tests:
mxcp: 1tool: name: hello description: Say hello to someone enabled: true
parameters: - name: name type: string description: Name of the person to greet examples: - "World" - "Alice"
return: type: string description: A friendly greeting message
source: file: ../sql/hello.sql
tests: - name: greet_world description: Test greeting World arguments: - key: name value: "World" result: "Hello, World!"
- name: greet_alice description: Test greeting Alice arguments: - key: name value: "Alice" result_contains_text: "Alice"Run the tests:
mxcp testOutput:
Testing tool/hello... ✓ greet_world ✓ greet_alice
Tests: 2 passed, 0 failedStep 8: Check for Issues
Section titled “Step 8: Check for Issues”Run the linter to check for improvements:
mxcp lintThe linter checks for:
- Missing descriptions
- Missing examples
- Best practice violations
Verification
Section titled “Verification”Your project should now have:
hello-mxcp/├── mxcp-site.yml├── tools/│ └── hello.yml├── sql/│ └── hello.sql└── ... (other directories)You can verify everything works:
# Validate structuremxcp validate
# Run testsmxcp test
# Run the toolmxcp run tool hello --param name="Tutorial Complete"Understanding the Flow
Section titled “Understanding the Flow”When you run mxcp run tool hello --param name=World:
- Load - MXCP reads
tools/hello.yml - Validate Input - Checks
nameis a string - Read SQL - Loads
sql/hello.sql - Execute - Runs the query with
$name= “World” - Validate Output - Checks result matches return type
- Return - Displays the result
Inline SQL Alternative
Section titled “Inline SQL Alternative”Instead of a separate file, you can use inline SQL:
source: code: | SELECT 'Hello, ' || $name || '!' AS greetingExternal files are recommended for:
- Better version control
- Syntax highlighting in editors
- Reusable SQL across tools
Testing with AI Clients
Section titled “Testing with AI Clients”Your tool works with any MCP-compatible client:
Connect to Claude Desktop - Add to your Claude Desktop config:
{ "mcpServers": { "hello-mxcp": { "command": "mxcp", "args": ["serve"], "cwd": "/path/to/hello-mxcp" } }}Use MCP Inspector - Debug without an AI client:
npx @modelcontextprotocol/inspectorThe MCP Inspector lets you visually test tools, view parameters, and debug responses.
Common Issues
Section titled “Common Issues””No tool found with name…”
Section titled “”No tool found with name…””- Check the
namefield in your YAML matches what you’re calling - Run
mxcp listto see available tools
”File not found…”
Section titled “”File not found…””- Verify the path in
source.fileis correct - Paths are relative to the YAML file location
”Validation error…”
Section titled “”Validation error…””- Check YAML syntax (indentation matters)
- Ensure all required fields are present
- Run
mxcp validatefor detailed errors
Next Steps
Section titled “Next Steps”Now that you understand the basics:
- SQL Endpoints Tutorial - Build more complex queries
- Python Endpoints Tutorial - Add Python logic
- Endpoints Concept - Deep dive into endpoint types