This feature is only available when using Bifrost 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 Bifrost: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:
| Registered Name | LLM Sees |
|---|---|
calculator | bifrostInternal_calculator |
get_weather | bifrostInternal_get_weather |
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
| Aspect | Tool Hosting (In-Process) | External MCP Server |
|---|---|---|
| Latency | ~0.1ms (no network) | 10-500ms (network dependent) |
| Deployment | Part of your app | Separate process/service |
| Language | Go only | Any language |
| Configuration | Code only | config.json, API, or UI |
| State Access | Direct access | Via APIs |
| Scaling | Scales with app | Independent scaling |

