Skip to content
Star -

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
  • MXCP installed (pip install mxcp)
  • A terminal/command prompt

Initialize a new MXCP project:

Terminal window
mkdir hello-mxcp
cd hello-mxcp
mxcp init

This creates the basic structure:

hello-mxcp/
├── mxcp-site.yml
├── tools/
├── resources/
├── prompts/
├── evals/
├── python/
├── plugins/
├── sql/
├── drift/
└── audit/

Create tools/hello.yml:

mxcp: 1
tool:
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.sql

Let’s break down each part:

FieldPurpose
mxcp: 1Schema version (always 1)
nameUnique identifier for the tool
descriptionWhat the tool does (shown to AI)
enabledWhether to load this tool
parametersInput definitions
returnOutput definition
sourceWhere the implementation lives

Create sql/hello.sql:

SELECT 'Hello, ' || $name || '!' AS greeting

The $name syntax binds the name parameter from the tool definition. DuckDB handles the parameter substitution safely (preventing SQL injection).

Check that your tool is correctly defined:

Terminal window
mxcp validate

Expected output:

✓ tools/hello.yml (tool/hello)
Validation complete: 1 passed, 0 failed

Execute the tool from the command line:

Terminal window
mxcp run tool hello --param name=World

Output:

greeting
--------
Hello, World!

Try different names:

Terminal window
mxcp run tool hello --param name=Alice
mxcp run tool hello --param name="MXCP User"

See all available endpoints:

Terminal window
mxcp list

Output:

Endpoints:
Tools:
- hello: Say hello to someone
Resources:
(none)
Prompts:
(none)

Update tools/hello.yml to include tests:

mxcp: 1
tool:
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:

Terminal window
mxcp test

Output:

Testing tool/hello...
✓ greet_world
✓ greet_alice
Tests: 2 passed, 0 failed

Run the linter to check for improvements:

Terminal window
mxcp lint

The linter checks for:

  • Missing descriptions
  • Missing examples
  • Best practice violations

Your project should now have:

hello-mxcp/
├── mxcp-site.yml
├── tools/
│ └── hello.yml
├── sql/
│ └── hello.sql
└── ... (other directories)

You can verify everything works:

Terminal window
# Validate structure
mxcp validate
# Run tests
mxcp test
# Run the tool
mxcp run tool hello --param name="Tutorial Complete"

When you run mxcp run tool hello --param name=World:

  1. Load - MXCP reads tools/hello.yml
  2. Validate Input - Checks name is a string
  3. Read SQL - Loads sql/hello.sql
  4. Execute - Runs the query with $name = “World”
  5. Validate Output - Checks result matches return type
  6. Return - Displays the result

Instead of a separate file, you can use inline SQL:

source:
code: |
SELECT 'Hello, ' || $name || '!' AS greeting

External files are recommended for:

  • Better version control
  • Syntax highlighting in editors
  • Reusable SQL across tools

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:

Terminal window
npx @modelcontextprotocol/inspector

The MCP Inspector lets you visually test tools, view parameters, and debug responses.

  • Check the name field in your YAML matches what you’re calling
  • Run mxcp list to see available tools
  • Verify the path in source.file is correct
  • Paths are relative to the YAML file location
  • Check YAML syntax (indentation matters)
  • Ensure all required fields are present
  • Run mxcp validate for detailed errors

Now that you understand the basics:

  1. SQL Endpoints Tutorial - Build more complex queries
  2. Python Endpoints Tutorial - Add Python logic
  3. Endpoints Concept - Deep dive into endpoint types