Skip to main content
This guide walks you through creating custom YAML SQL tools from basic queries to advanced enterprise operations. You’ll learn to build tools that integrate seamlessly with AI agents while maintaining IBM i security and performance standards.
Prerequisites: Basic SQL knowledge and familiarity with IBM i system services (QSYS2 schema). For YAML syntax, any text editor will work, but one with YAML syntax highlighting is recommended.

Your First SQL Tool

Let’s start with a simple tool that lists active jobs. This example introduces the core concepts you’ll use in all YAML SQL tools.

Step 1: Create the Configuration File

Create a new file called my-first-tools.yaml:

Step 2: Test Your Tool

Start the MCP server with your new configuration:
Use the MCP Inspector to test your tool:
Development Tip: Always start with simple, parameter-free tools to verify your connection and SQL syntax. You can add complexity incrementally as you gain confidence with the YAML structure.

Adding Parameters

Parameters make tools dynamic and reusable. Let’s enhance our job listing tool with filtering capabilities:

Parameter Examples Guide

Need comprehensive examples? See the Parameter Guide for detailed examples of all parameter types (string, integer, float, boolean, array) with validation patterns and best practices.

Parameter Validation

The MCP server automatically validates parameters before executing SQL:
Security Note: Parameter validation is your first line of defense against invalid input. Always include appropriate constraints, especially for string parameters that could be used in injection attacks.

Complete Example: Employee Information Tools

The tools/sample/employee-info.yaml file demonstrates a comprehensive set of tools using the IBM i SAMPLE schema. This example showcases all five parameter types, validation patterns, and SQL techniques in a single, production-ready configuration.
Why This Example Matters: Rather than showing isolated snippets, this complete file demonstrates how real-world tools are structured, how parameters work together, and how SQL patterns combine to create powerful data operations.

Overview

File Location: tools/sample/employee-info.yaml Purpose: Provide HR and project management capabilities using IBM i’s SAMPLE database (EMPLOYEE, DEPARTMENT, PROJECT tables) What You’ll Learn:
  • All 5 parameter types (string, integer, float, boolean, array) in production context
  • Real-world SQL patterns: joins, self-joins, aggregations, pagination
  • Parameter validation strategies
  • Toolset organization for discoverability

Source Configuration

Every YAML file starts with a source definition:
Source Reuse: This source is reused by all 8 tools in the file. Define sources once at the top, reference them in each tool using the source field. This ensures consistent connection settings and simplifies credential management.

Tool 1: String Parameters with Pattern Validation

Tool: get_employee_details Demonstrates: String pattern validation, table joins, self-joins for hierarchical data
Key Techniques:
  • Pattern validation: ^[0-9]{6}$ enforces exactly 6 digits
  • LEFT JOIN: Handles missing departments or managers gracefully
  • Self-join: EMPLOYEE M retrieves manager information by joining EMPLOYEE to itself
  • Descriptive aliases: MGR_FIRSTNME, MGR_LASTNAME clarify the data source
MCP Tool Call:

Tool 2 & 3: String Enum Parameters

Tools: find_employees_by_department, find_employees_by_job Demonstrates: Enum constraints for controlled value selection
Enum Parameters: Enum parameters automatically enhance descriptions for LLMs: “Must be one of: ‘A00’, ‘B01’, ‘C01’…”. This provides autocomplete-like guidance and prevents invalid queries. Use enums whenever you have a fixed set of valid values.

Tool 4: Boolean Parameters

Tool: get_employee_projects Demonstrates: Boolean flags for conditional filtering, complex multi-table joins
Key Techniques:
  • Boolean in SQL: :include_completed = 1 (true) or = 0 (false)
  • Conditional filtering: (:include_completed = 1 OR EPA.EMENDATE IS NULL) filters active projects when false
  • 4-table joins: Connects employee project activities with projects, project activities, and activity descriptions
  • Default value: Makes parameter optional (defaults to showing all projects)
Usage Examples:

Tool 5: Integer Parameters with Aggregations

Tool: get_department_salary_stats Demonstrates: Multiple optional integers, default values, SQL aggregations
Key Techniques:
  • Integer constraints: min: 0, max: 100000 prevent invalid salary ranges
  • Aggregation functions: COUNT, AVG, MIN, MAX, SUM provide statistical summaries
  • GROUP BY: Groups results by department for aggregate calculations
  • Special value pattern: '*ALL' provides “all departments” option
  • NULL handling: OR :min_salary IS NULL allows optional filtering
Default Values: Integer parameters with default values don’t need required: false. The presence of a default makes them optional automatically. This pattern works for all parameter types.

Tool 6: Array Parameters

Tool: find_project_team_members Demonstrates: Array parameters with SQL IN clauses, array length constraints
Key Techniques:
  • Array expansion: IN (:project_ids) automatically expands to IN (?, ?, ?) with safe parameter binding
  • itemType: Specifies that array contains strings (also supports integer, float, boolean)
  • Length constraints: minLength: 1 ensures at least one ID, maxLength: 10 prevents overly broad queries
  • Example in description: Guides LLM on correct JSON array format
MCP Tool Call:
Array Input Format: Arrays must be passed as JSON arrays, not strings:
  • ✅ Correct: {"project_ids": ["MA2100", "AD3100"]}
  • ❌ Incorrect: {"project_ids": "('MA2100', 'AD3100')"}

Tool 7: Float Parameters

Tool: calculate_employee_bonus Demonstrates: Float parameters for decimal calculations, mathematical operations
Key Techniques:
  • Float type: Allows decimal values (0.1, 0.15, 0.25, etc.)
  • Range constraints: min: 0.0, max: 0.3 limits multiplier to 0-30%
  • SQL arithmetic: E.SALARY * :performance_multiplier performs calculation
  • Combined parameters: String pattern + float calculation in single tool
Usage:

Tool 8: Pagination with Multiple Parameters

Tool: search_employees Demonstrates: LIMIT/OFFSET pagination, case-insensitive search, partial matching
Key Techniques:
  • minLength: minLength: 2 prevents single-character searches that return too many results
  • Pagination pattern: LIMIT :page_size OFFSET (:page_number - 1) * :page_size
  • Case-insensitive search: UPPER(column) LIKE UPPER(pattern)
  • Partial matching: '%' || :name_search || '%' finds names containing the search term
  • Multiple integer parameters: page_size and page_number with sensible defaults
Usage:

Toolset Organization

The file defines 3 toolsets to organize the 8 tools by functional area:
Selective Loading: Toolsets enable selective loading. Load only what you need:
  • --toolsets employee_information loads just employee lookup tools
  • --toolsets employee_information,salary_analysis loads two categories
  • Omit --toolsets to load everything
This improves startup time and reduces API surface for focused agents.

Running the Example

List available toolsets:
Start server with specific toolsets:

Parameter Type Summary

This example demonstrates all five parameter types across eight tools:
ToolStringIntegerFloatBooleanArray
get_employee_details✅ (pattern)
find_employees_by_department✅ (enum)
find_employees_by_job✅ (enum)
get_employee_projects✅ (pattern)
get_department_salary_stats✅ (default)✅ (optional)
find_project_team_members
calculate_employee_bonus✅ (pattern)
search_employees✅ (minLength)✅ (pagination)

SQL Techniques Demonstrated

This file also showcases essential SQL patterns for IBM i development:

Joins

  • INNER JOIN: Connecting related tables
  • LEFT JOIN: Handling optional relationships
  • Self-join: Hierarchical data (manager lookup)
  • Multi-table joins: 4-way joins for complex data

Aggregations

  • COUNT: Counting records
  • AVG, MIN, MAX, SUM: Statistical calculations
  • GROUP BY: Grouping for aggregates

Filtering

  • WHERE clauses: Basic and conditional filtering
  • IN clauses: Array-based filtering
  • NULL handling: Optional parameter patterns
  • Special values: *ALL pattern for “all records”

Search & Pagination

  • LIKE with wildcards: Partial matching
  • UPPER(): Case-insensitive search
  • LIMIT/OFFSET: Pagination pattern
  • ORDER BY: Sorting results

Common IBM i Patterns

Here are proven patterns for working with IBM i system services:

System Information Queries

Library and Object Management

Database Analysis

Advanced Features

Response Formatting

Control how results are presented to AI agents:

Security Configuration

Mark sensitive operations for audit logging and access control:

Error Handling and Validation

Build robust tools with comprehensive error handling:

Testing and Debugging

Validation Commands

Test your YAML configuration before deployment:
For complete testing strategies including MCP Inspector usage, see the Quick Start Guide. For production testing, refer to the Production Deployment guide.

Debug Mode

Enable debug logging to troubleshoot tool execution:

Common Issues and Solutions

Problem: Parameter :parameter_name not found in statementSolution: Ensure parameter names in the statement match exactly with parameter definitions:
Problem: SQL statement fails to executeSolution: Test SQL separately in a DB2 client first:
Problem: SQL0551: Not authorized to objectSolution: Verify user has appropriate authorities:
Problem: Cannot connect to IBM i systemSolution: Verify connection parameters and Mapepire daemon:

File Organization Best Practices

Single Domain Approach

Organize tools by business domain or functional area:

Multi-Environment Support

Use environment-specific configurations:

Version Control

Include metadata for tool versioning and maintenance:

Performance Considerations

Query Optimization

Always include appropriate performance optimizations:

Connection Pooling

The MCP server automatically manages connection pooling, but you can optimize usage:

Next Steps

Testing Guide

Learn how to test and debug your SQL tools effectively

Examples & Patterns

Explore real-world examples and advanced patterns

Agent Integration

Build AI agents that use your custom SQL tools

Production Deployment

Deploy your tools to production with monitoring
Tool Design Philosophy: Effective SQL tools balance three concerns: usability (clear parameters and descriptions for AI agents), security (proper validation and authority checking), and performance (efficient queries that respect system resources). Start simple and add complexity incrementally as you understand your specific use cases.