Skip to main content

Model Context Protocol (MCP) Implementation in ValkyrAI

ValkyrAI implements the Model Context Protocol (MCP) as both a consumer and publisher of context-driven AI services. This protocol enables ValkyrAI's microservices, agents, and external tools to exchange critical context (e.g., code snippets, assets, user preferences) in a consistent, protocol-driven manner.

What is MCP?

The Model Context Protocol (MCP) is a specification for packaging, transmitting, and consuming context between AI models, code generation services, user interface components, and more. MCP is designed to ensure:

  • Consistency: Standardized data structure and message format
  • Extensibility: Seamless addition of new context types (preferences, assets, code stubs, etc.)
  • Interoperability: Integration across ValkyrAI, ThorAPI, ValorIDE, and external services via a shared protocol

ValkyrAI as an MCP Consumer

As an MCP consumer, ValkyrAI can leverage services provided by other MCP-compliant systems:

Code Generation Services

ValkyrAI can request code generation from ThorAPI or other MCP-compliant code generators:

{
"request": {
"type": "code_generation",
"language": "java",
"framework": "spring",
"description": "Create a REST controller for user management"
}
}

Asset Generation

ValkyrAI can request asset generation from MCP-compliant services:

{
"request": {
"type": "asset_generation",
"asset_type": "image",
"prompt": "A futuristic city skyline with flying vehicles",
"parameters": {
"width": 1024,
"height": 768,
"style": "photorealistic"
}
}
}

Data Transformation

ValkyrAI can request data transformation services:

{
"request": {
"type": "data_transformation",
"source_format": "csv",
"target_format": "json",
"data": "..."
}
}

ValkyrAI as an MCP Publisher

As an MCP publisher, ValkyrAI provides services to other MCP-compliant systems:

Workflow Management

ValkyrAI exposes its workflow management capabilities via MCP:

{
"service": "workflow_management",
"operations": [
{
"name": "create_workflow",
"parameters": {
"name": "string",
"description": "string",
"tasks": "array"
}
},
{
"name": "start_workflow",
"parameters": {
"id": "string"
}
},
{
"name": "get_workflow_status",
"parameters": {
"id": "string"
}
}
]
}

SecureField Encryption

ValkyrAI exposes SecureField encryption services via MCP:

{
"service": "secure_field",
"operations": [
{
"name": "encrypt",
"parameters": {
"data": "string",
"field_type": "string"
}
},
{
"name": "decrypt",
"parameters": {
"encrypted_data": "string"
}
}
]
}

Code Generation

ValkyrAI exposes ThorAPI code generation capabilities via MCP:

{
"service": "code_generation",
"operations": [
{
"name": "generate_spring_boot",
"parameters": {
"openapi_spec": "string",
"options": "object"
}
},
{
"name": "generate_typescript_client",
"parameters": {
"openapi_spec": "string",
"options": "object"
}
}
]
}

MCP Integration in ValkyrAI Components

Workflow Engine

The ValkyrAI Workflow Engine integrates with MCP to enable:

  • Dynamic configuration of workflow tasks based on MCP context
  • Execution of MCP service calls as part of workflow tasks
  • Publishing workflow status and results as MCP context

Example of an MCP-enabled workflow task:

{
"id": "generate-code",
"type": "mcp",
"parameters": {
"service": "code_generation",
"operation": "generate_spring_boot",
"parameters": {
"openapi_spec": "${workflow.inputs.openapi_spec}",
"options": {
"package": "com.example",
"generate_tests": true
}
}
}
}

SecureFieldKMS

The SecureFieldKMS integrates with MCP to enable:

  • Secure exchange of encryption keys via MCP
  • Key rotation operations triggered by MCP requests
  • Encryption and decryption services exposed via MCP

HeimdaLLM

HeimdaLLM integrates with MCP to enable:

  • Dynamic configuration of LLM parameters via MCP
  • Sharing of LLM-generated content as MCP context
  • Orchestration of multiple LLM services via MCP

MCP Server Configuration

ValkyrAI can be configured as an MCP server by adding the appropriate configuration to the mcp-servers.json file:

{
"servers": [
{
"id": "valkyrai-workflow",
"name": "ValkyrAI Workflow Engine",
"description": "MCP server for ValkyrAI workflow management",
"endpoint": "http://localhost:8080/api/mcp/workflow",
"auth": {
"type": "bearer",
"token_endpoint": "http://localhost:8080/api/auth/token"
}
},
{
"id": "valkyrai-securefield",
"name": "ValkyrAI SecureField",
"description": "MCP server for SecureField encryption services",
"endpoint": "http://localhost:8080/api/mcp/securefield",
"auth": {
"type": "bearer",
"token_endpoint": "http://localhost:8080/api/auth/token"
}
}
]
}

MCP Client Configuration

To configure ValkyrAI as an MCP client, add the following to the application.yaml file:

valkyrai:
mcp:
clients:
- id: thorapi-codegen
name: ThorAPI Code Generation
endpoint: http://localhost:8081/api/mcp
auth:
type: bearer
token: ${THORAPI_MCP_TOKEN}
- id: valoride-tools
name: ValorIDE Tools
endpoint: http://localhost:8082/api/mcp
auth:
type: bearer
token: ${VALORIDE_MCP_TOKEN}

MCP Roadmap in ValkyrAI

ValkyrAI's MCP implementation roadmap includes:

1. ThorAPI CodeGen as an MCP service

  • Expose ThorAPI's code generation functionality via a standard MCP endpoint
  • Enable external services to request code generation with consistent request/response structures

2. Utilize MCP as ValorIDE tooling

  • Leverage MCP to push/pull context (e.g., code snippets, frameworks, libraries) into ValorIDE
  • Automate snippet retrieval via MCP for frictionless, standardized code injection

3. Utilize MCP as ValkyrAI tooling

  • Enable ValkyrAI's internal modules, microservices, or agentic subroutines to communicate seamlessly
  • Allow each subcomponent to publish new context or subscribe to relevant context from other modules

4. MCP Publishing Protocol (Over RSS)

  • Implement a simple, RSS-based method for publishing new or updated context
  • Enable easy integration with existing feed readers for external integrators

5. Component Library Generator

  • Provide end-to-end generation of front-end or back-end component libraries as an MCP service
  • Allow users to define schemas or configs for needed components

6. Preferences Stack

  • Create a centralized location for storing/retrieving dev or user preferences
  • Ensure consistent scaffolding across teams/projects without requiring repeated manual steps

7. Gridheim Sheetster Integration

  • Extend Gridheim Sheetster with an MCP endpoint for formula logic, data transformations, or import/export routines
  • Enable embedding of spreadsheet functionality in any service that can speak MCP

8. Asset Generation

  • Centralize calls to multiple ML models behind one MCP endpoint for generating images, audio, or other assets
  • Reduce complexity by providing a single interface that routes to the correct model

9. Dynamic Inference Stack Configuration

  • Enable agents to reconfigure or switch inference models on-the-fly through MCP requests
  • Adapt to changing tasks in real time by switching between different specialized models

Best Practices for MCP in ValkyrAI

Security Considerations

  • Always use authentication for MCP endpoints
  • Encrypt sensitive data in MCP requests and responses
  • Implement rate limiting to prevent abuse
  • Validate all incoming MCP requests

Performance Optimization

  • Use caching for frequently requested MCP context
  • Implement pagination for large context responses
  • Consider asynchronous processing for time-consuming operations
  • Monitor MCP endpoint performance

Integration Guidelines

  • Document all MCP endpoints and operations
  • Provide example requests and responses
  • Implement versioning for MCP endpoints
  • Include error handling and detailed error messages

Conclusion

The Model Context Protocol (MCP) is a powerful feature of ValkyrAI that enables seamless integration with other AI-powered services and tools. By implementing MCP as both a consumer and publisher, ValkyrAI can leverage external services and provide its own capabilities to other systems, creating a rich ecosystem of interoperable AI tools.

For more information on MCP, refer to the Model Context Protocol specification and the ValkyrAI API documentation.