Skip to content
cccskills
FreePublished on GitHub

hamilton-mcp

Build Hamilton data pipelines interactively with MCP tools. Create starter code, validate dependencies and syntax, inspect or visualize the DAG, then execute it with inputs. This workflow helps you develop and debug pipelines through a guided feedback loop in a conversation.

OriginalShow the original description

Interactive Hamilton DAG development via MCP tools. Validate, visualize, scaffold, and execute Hamilton pipelines without leaving the conversation. Use when building or debugging Hamilton dataflows interactively.

apache/hamilton2,621 stars(GitHub 2,621 + cccskills 0)

Run score Not tested

See how to install

Good for

  • Scaffolding a new Hamilton pipeline
  • Checking DAG dependencies before execution
  • Visualizing pipeline structure
  • Debugging a Hamilton dataflow interactively

Files included (1)

  • SKILL.md7.6 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

<!-- SPDX-License-Identifier: Apache-2.0 -->

Hamilton MCP Server -- Interactive DAG Development

The Hamilton MCP server exposes Hamilton's DAG compilation, validation, and execution as interactive tools. It enables a tight feedback loop: write functions, validate the DAG, visualize dependencies, fix errors, and execute -- all without leaving the conversation.

Setup

Run via uvx (recommended). Add --with for whichever libraries your code uses:

uvx --from "apache-hamilton[mcp]" hamilton-mcp                              # minimal
uvx --from "apache-hamilton[mcp]" --with pandas --with numpy hamilton-mcp   # pandas/numpy project
uvx --from "apache-hamilton[mcp]" --with polars hamilton-mcp                # polars project

Or install and run directly:

pip install "apache-hamilton[mcp]"
hamilton-mcp

Or use programmatically:

from hamilton.plugins.h_mcp import get_mcp_server

mcp = get_mcp_server()
mcp.run()

Workflow: The Golden Path

Always follow this sequence when building Hamilton DAGs interactively:

ask user -> capabilities -> scaffold -> validate -> visualize -> correct -> execute

Step 1: Ask the User Which Libraries They Use

Before calling any tool, ask the user which data libraries they use (pandas, numpy, polars, etc.). Then pass their answer as preferred_libraries to hamilton_capabilities and hamilton_scaffold. This ensures scaffolds match the user's project, not the server's environment.

// Example: user says "I use pandas"
// Tool call: hamilton_capabilities(preferred_libraries=["pandas"])
{
  "libraries": {
    "pandas": true,
    "numpy": true,
    "polars": false,
    "graphviz": true
  },
  "available_scaffolds": [
    "basic", "basic_pure_python", "config_based",
    "data_pipeline", "parameterized"
  ]
}

Decision rules:

  • If user says pandas: use pandas-based scaffolds and DataFrame/Series types
  • If user has no preference or only uses built-in types: use basic_pure_python scaffold and int/float/str/dict types
  • If graphviz is available: use hamilton_visualize to show the DAG structure
  • Never generate code that imports libraries the user hasn't stated they use

Step 2: Scaffold a Starting Point

Use hamilton_scaffold with a pattern name from the capabilities response:

PatternLibraries RequiredUse Case
basic_pure_pythonNoneSimple pipelines with built-in types
basicpandasDataFrame cleaning & counting
parameterizedpandasMultiple nodes from one function
config_basedpandasEnvironment-conditional logic
data_pipelinepandasETL: ingest, clean, transform, aggregate
ml_pipelinepandas, numpyFeature engineering & train/test split
data_qualitypandas, numpyValidation with @check_output

Step 3: Validate Before Executing

Always validate before executing. hamilton_validate_dag compiles the DAG without running it, catching:

  • Syntax errors
  • Missing dependencies (parameter names that don't match any function)
  • Type annotation issues
  • Circular references
// Success response
{
  "valid": true,
  "node_count": 5,
  "nodes": ["cleaned", "feature_a", "feature_b", "raw_data", "result"],
  "inputs": ["data_path"],
  "errors": []
}
// Failure response
{
  "valid": false,
  "node_count": 0,
  "nodes": [],
  "inputs": [],
  "errors": [{"type": "SyntaxError", "message": "...", "detail": "line 5"}]
}

Self-correction loop: If validation fails, read the error, fix the code, and validate again. Do not proceed to execution until validation passes.

Step 4: Visualize the DAG (if graphviz available)

hamilton_visualize returns DOT graph source. Use this to:

  • Confirm dependency structure matches intent
  • Identify unexpected connections
  • Explain the pipeline to the user

Step 5: Explore Node Details

hamilton_list_nodes returns structured info for every node:

  • Name, output type, documentation
  • Whether it's an external input (must be provided at runtime)
  • Required and optional dependencies

Use this to understand what inputs the DAG needs before execution.

Step 6: Execute

hamilton_execute runs the DAG with provided inputs and returns results. Key parameters:

  • code: The full Python source
  • final_vars: List of node names to compute (only these and their dependencies run)
  • inputs: Dict of external input values
  • timeout_seconds: Safety limit (default 30s)

WARNING: This executes arbitrary Python code. Always validate first.

Error Handling & Self-Correction

Common Errors and Fixes

"No module named 'X'" The code imports a library that isn't installed. Call hamilton_capabilities to check availability, then rewrite without the missing library.

"Missing dependencies: ['node_name']" A function parameter doesn't match any function name or external input. Either:

  1. Add a function with that name, or
  2. Include it in inputs when executing

"Execution timed out after Ns" The code takes too long. Reduce data size, simplify computation, or increase timeout_seconds.

Validation passes but execution fails Validation checks structure, not runtime behavior. Common causes:

  • Missing input values at execution time
  • Runtime exceptions in function bodies (division by zero, key errors)
  • Library-specific errors (e.g., column not found in DataFrame)

Retry Strategy

  1. If a tool returns an error, fix the issue in code and retry once
  2. If the same error recurs, explain the issue to the user and ask for guidance
  3. Never retry more than twice on the same error

Tool Reference

ToolPurposeWhen to Use
hamilton_capabilitiesEnvironment discoveryAlways first
hamilton_scaffoldGenerate starter codeStarting a new pipeline
hamilton_validate_dagCompile-time validationBefore every execution
hamilton_list_nodesInspect DAG structureUnderstanding dependencies
hamilton_visualizeDOT graph generationExplaining structure (requires graphviz)
hamilton_executeRun the DAGAfter successful validation
hamilton_get_docsHamilton documentationLearning decorators, patterns

Environment Fallbacks

If the MCP server is not running: Fall back to CLI:

# Validate a module
python -c "from hamilton import driver; import my_module; dr = driver.Builder().with_modules(my_module).build(); print('Valid!')"

If Hamilton is not installed: Provide the user with installation instructions:

uvx --from "apache-hamilton[mcp]" hamilton-mcp   # Run via uvx (add --with <lib> as needed)
pip install "apache-hamilton[mcp]"              # Or install directly

Success Criteria

A successful MCP interaction produces:

  1. Code that passes hamilton_validate_dag with zero errors
  2. All external inputs identified via hamilton_list_nodes
  3. Execution results returned from hamilton_execute
  4. The user understands the DAG structure (via visualization or node listing)

Additional Resources

  • For core Hamilton patterns: use /hamilton-core
  • For scaling with async/Spark: use /hamilton-scale
  • For LLM workflow patterns: use /hamilton-llm
  • For observability: use /hamilton-observability
  • Hamilton documentation: hamilton_get_docs("overview")

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

hamilton-core

FreeSummary

Build and work with dataflow DAGs in Apache Hamilton using Python functions and decorators. This skill helps structure transformations, configure execution with a Driver, test functions, visualize dependencies, and debug common issues such as missing dependencies or cycles.

  • Creating a Hamilton data transformation DAG
  • Converting a script into reusable functions
  • Testing or debugging a dataflow
apache/hamilton2.6KUpdated Oct 28, 2026

Build a Hamilton dataflow from a new module by turning requirements into a DOT graph, defining Python function signatures, validating the DAG, and implementing each node with tests. The workflow also covers pragmatic type annotations and runtime type inference.

  • Designing a Hamilton DAG from pipeline requirements
  • Validating graph structure before implementing functions
  • Building pipeline nodes incrementally with test-driven development
apache/hamilton2.6KUpdated Oct 28, 2026

Integrate Hamilton dataflows with tools such as Airflow, Dagster, FastAPI, Streamlit, Jupyter, MLflow, and dbt. Use the patterns to schedule pipelines, serve predictions, explore results interactively, or track experiments and models.

  • Scheduling Hamilton pipelines with Airflow or Dagster
  • Serving Hamilton predictions through a web API
  • Building interactive analytics with Streamlit or Jupyter
apache/hamilton2.6KUpdated Oct 28, 2026

hamilton-llm

FreeSummary

Design LLM workflows with Hamilton, including RAG pipelines that retrieve relevant text, embeddings, vector databases, modular prompts, and structured outputs. Explore patterns for asynchronous calls, provider choices, caching, agent steps, and testing each part of an AI application.

  • Building a RAG question-answering pipeline
  • Creating modular and testable prompts
  • Running independent LLM calls concurrently
apache/hamilton2.6KUpdated Oct 28, 2026

Track Hamilton dataflow runs in the UI and SDK to inspect execution history, dependencies, inputs, outputs, errors, and timing. Use the recorded details to debug failed runs, compare executions, follow data lineage, and monitor production workflows.

  • Inspecting a failed pipeline run
  • Comparing development and production runs
  • Tracing data dependencies across pipelines
apache/hamilton2.6KUpdated Oct 28, 2026

hamilton-scale

FreeSummary

Choose ways to improve Hamilton workflow performance based on the workload. Learn when to use async I/O, multithreading, Spark, Ray, or Dask, and how caching can avoid repeated computation. The examples cover parallel execution and distributed processing for larger tasks.

  • Parallelizing independent API or database calls
  • Processing datasets larger than one machine can hold
  • Distributing Python or machine learning computation
apache/hamilton2.6KUpdated Oct 28, 2026

See all skills by apache

Report a problem with this skill