This feature is only available when using ModRouter as a Go SDK. It is not available in the Gateway deployment.
Overview
Tool Hosting allows you to register custom tools directly within your Go application. These tools run in-process with zero network overhead, making them ideal for:- Application-specific business logic
- High-performance operations
- Testing and development
- Tools that need access to application state
bifrostInternal) when you register your first tool.
Basic Usage
Step 1: Define Your Tool Schema
Create a schema that describes your tool’s parameters:Step 2: Implement the Handler
Create a function that handles tool execution:Step 3: Register the Tool
Register your tool with ModRouter:Complete Example
Here’s a complete example with multiple tools:Typed Handlers
For better type safety, use typed structs with JSON marshaling:Tool Naming
Tool names fromRegisterMCPTool are prefixed with bifrostInternal- when exposed to LLMs:
This prevents naming conflicts with tools from external MCP servers.
bifrostInternal is the current Go SDK runtime client key; it is not product branding.
Error Handling
Return errors from your handler to indicate tool execution failures:Accessing Application State
Since tools run in-process, they can access your application’s state:Best Practices
Validate inputs
Validate inputs
Always validate arguments before processing:
Return structured data
Return structured data
Return JSON for complex responses:
Handle timeouts
Handle timeouts
Use context for long-running operations:
Log for debugging
Log for debugging
Add logging for troubleshooting:
Comparison with External MCP Servers
Next Steps
Tool Execution
Learn how tool execution works
Agent Mode
Enable auto-execution for hosted tools
