Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .github/workflows/mcp-integration-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: MCP Integration Test

on:
pull_request:
branches: [ "main" ]
push:
branches: [ "main" ]
workflow_dispatch:

permissions:
contents: read

jobs:
mcp-test:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
node-version: [18.x, 20.x]

steps:
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache-dependency-path: mcp/package-lock.json

- name: Install MCP dependencies
working-directory: ./mcp
run: npm ci

- name: Run MCP integration tests
working-directory: ./mcp
run: npm test

- name: Test MCP server startup
working-directory: ./mcp
run: |
# Test that the MCP server can start without errors
timeout 10s node server.js 2>&1 | tee server_output.log || true
# Check if server started successfully
if grep -q "MCP server running" server_output.log; then
echo "✅ MCP server started successfully"
else
echo "❌ MCP server failed to start"
cat server_output.log
exit 1
fi

- name: Validate MCP configuration
working-directory: ./mcp
run: |
# Check if configuration file is valid JSON
node -e "
const config = require('./mcp-config.json');
console.log('✅ MCP configuration is valid JSON');
console.log('Tools available:', Object.keys(config.tools).length);
console.log('Resources available:', Object.keys(config.resources).length);
console.log('AI scenarios:', config.aiAgentScenarios.length);
"

- name: Check library build capability (if CUDA available)
run: |
# Check if we can at least configure the build
if command -v cmake &> /dev/null; then
echo "✅ CMake available, testing configuration..."
mkdir -p build
cd build
cmake -DENABLE_CUDA=OFF -DCMAKE_BUILD_TYPE=Release .. || echo "⚠️ Build configuration needs adjustment for CI environment"
else
echo "⚠️ CMake not available in CI environment"
fi
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ CMakeFiles/
cmake_install.cmake
Makefile
CTestTestfile.cmake
Testing/
Testing/

# MCP Integration
mcp/node_modules/
mcp/package-lock.json
mcp/server_output.log
*.log
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,40 @@ This novel type of Horizontal Fusion, allows to Horizontally Fuse kernels that a

This has been tested before, by creating special compilers that generate the assembly code, and the performance benefits have been already reported. The novelty in our approach is that we do not require a different compiler. We do this by leveraging the C++17 capabilities found in nvcc.

## MCP Integration for AI Agents

The FusedKernelLibrary now includes Model Context Protocol (MCP) server integration, enabling AI agents to interact with and test the library through a standardized interface.

### AI Agent Capabilities

Through the MCP integration, AI agents can:
- **Discover** library capabilities and documentation
- **Build** the library with configurable options (CPU/CUDA backends)
- **Execute** comprehensive test suites
- **Generate** fusion kernel code examples
- **Validate** code implementations against the library API
- **Analyze** system requirements and CUDA support

### Quick Start with MCP

```bash
# Navigate to MCP integration directory
cd mcp

# Install dependencies
npm install

# Start MCP server
npm start

# Run AI agent tests
npm test
```

The MCP server provides tools for building, testing, and validating FusedKernelLibrary code, making it ideal for AI-assisted development and automated code generation workflows.

For detailed MCP integration documentation, see [mcp/README.md](mcp/README.md).

## Closed source friendly

A company that has it's own CUDA kernels, and wants to start fusing them along with operations present in this library, can do so by shaping their kernels into a conformant FusedKernel Operation, that can be passed as a template parameter of one of the FKL InstantiableOperation structs.
Expand Down
225 changes: 225 additions & 0 deletions mcp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
# FusedKernelLibrary MCP Integration

This directory contains the Model Context Protocol (MCP) server integration for the FusedKernelLibrary, enabling AI agents to interact with and test the library through a standardized interface.

## Overview

The MCP integration provides AI agents with:
- **Tools** to build, test, and validate the library
- **Resources** to access documentation and configuration
- **Examples** to understand usage patterns and API

## Quick Start

### Prerequisites

- Node.js 18.0+
- npm or yarn
- FusedKernelLibrary source code
- Optional: CUDA toolkit for GPU functionality

### Installation

```bash
cd mcp
npm install
```

### Running the MCP Server

```bash
npm start
```

The server runs on stdio and communicates using the MCP protocol.

### Testing the Integration

```bash
npm test
```

## Available Tools

### `build_library`
Builds the FusedKernelLibrary using CMake with configurable options.

**Parameters:**
- `buildType`: "Debug" or "Release" (default: "Release")
- `enableCuda`: boolean (default: true)
- `enableCpu`: boolean (default: true)

### `run_tests`
Executes the library test suite.

**Parameters:**
- `testType`: "all", "unit", "standard", or "benchmark" (default: "all")
- `verbose`: boolean (default: false)

### `get_library_info`
Retrieves comprehensive information about the library capabilities.

### `check_cuda_support`
Verifies CUDA availability and configuration on the system.

### `list_examples`
Lists all available code examples and patterns in the library.

### `validate_code_example`
Validates code examples against the library API.

**Parameters:**
- `examplePath`: string (required) - Path to the example file

## Available Resources

### `fusedkernel://readme`
Access to the main README.md documentation.

### `fusedkernel://cmake-config`
Access to the CMakeLists.txt configuration.

### `fusedkernel://examples`
JSON listing of available code examples.

## AI Agent Scenarios

The MCP integration supports several AI agent testing scenarios:

### 1. Library Discovery
- AI agent discovers library capabilities
- Reads documentation and examples
- Understands fusion techniques and API

### 2. Build and Test Workflow
- AI agent checks system requirements (CUDA)
- Builds library with appropriate configuration
- Runs comprehensive test suite

### 3. Code Generation and Validation
- AI agent examines existing examples
- Generates new fusion code patterns
- Validates generated code against library API

## Configuration

The `mcp-config.json` file contains:
- Server configuration
- Resource definitions
- Tool descriptions
- AI agent scenario definitions

## Usage Examples

### Basic MCP Client Interaction

```javascript
// Example MCP request to build the library
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "build_library",
"arguments": {
"buildType": "Release",
"enableCuda": true
}
}
}
```

### Resource Access

```javascript
// Example MCP request to read documentation
{
"jsonrpc": "2.0",
"id": 2,
"method": "resources/read",
"params": {
"uri": "fusedkernel://readme"
}
}
```

## Integration with AI Systems

This MCP server can be integrated with:

- **Claude Desktop** - Add to MCP server configuration
- **VS Code with MCP extensions**
- **Custom AI agents** using MCP client libraries
- **GitHub Copilot** for enhanced code assistance

### Claude Desktop Configuration

Add to your Claude Desktop configuration:

```json
{
"mcpServers": {
"fused-kernel-library": {
"command": "node",
"args": ["./mcp/server.js"],
"cwd": "/path/to/FusedKernelLibrary"
}
}
}
```

## Development

### Adding New Tools

1. Add tool definition to `setupToolHandlers()` in `server.js`
2. Implement the tool handler method
3. Update the configuration in `mcp-config.json`
4. Add tests to `test/mcp-client-test.js`

### Adding New Resources

1. Add resource definition to `setupResourceHandlers()` in `server.js`
2. Implement the resource reader method
3. Update configuration and documentation

## Troubleshooting

### Common Issues

**Server won't start:**
- Check Node.js version (requires 18.0+)
- Verify all dependencies are installed: `npm install`
- Check for port conflicts

**Build failures:**
- Ensure CMake is available in PATH
- Check CUDA toolkit installation for GPU builds
- Verify compiler compatibility

**Test failures:**
- Build the library first: use `build_library` tool
- Check system requirements (CUDA for GPU tests)
- Review verbose test output

### Debug Mode

Run the server with debug logging:

```bash
NODE_ENV=development node server.js
```

## Contributing

When adding new functionality:

1. Follow the existing code patterns
2. Add appropriate error handling
3. Update documentation
4. Add test cases
5. Ensure MCP protocol compliance

## License

This MCP integration follows the same license as the FusedKernelLibrary project.
Loading