Octopus
As MCP Tools
AI Functions with an InputSchema defined are automatically registered as MCP tools in the MCPToolRegistry when the agent loads. The LLM sees them alongside C# tools and uses them in the same tool call loop — the execution difference is invisible to the LLM.
Automatic MCP Registration
When an agent is initialised, the AIFunctionToolRegistrar queries all active AI Functions for that agent and tenant, then registers each one as an MCPTool:
public class AIFunctionToolRegistrar
{
public async Task RegisterForAgentAsync(
Guid agentId, Guid tenantId,
MCPToolRegistry registry,
CancellationToken ct)
{
// Load all active AI Functions for this agent + shared tenant functions
var functions = await _store.GetActiveForAgentAsync(agentId, tenantId, ct);
foreach (var fn in functions.Where(f => f.InputSchema != null))
{
registry.Register(new MCPTool
{
Schema = new ToolDefinition
{
Name = fn.Name,
Description = fn.Description ?? fn.Name,
InputSchema = JsonDocument.Parse(fn.InputSchema!)
},
Handler = async (input, ctx, ct2) =>
{
var result = await _runtime.ExecuteAsync(fn, input, new AIFunctionContext
{
AgentId = ctx.AgentId,
UserId = ctx.UserId,
TenantId = ctx.TenantId
}, ct2);
return JsonSerializer.Serialize(result);
}
});
}
}
}
Creating an AI Function MCP Tool — Step by Step
1
Write the Function Code
Write a JavaScript
execute(input) function that performs the desired logic.
2
Define Name and Description
Give the function a unique name (snake_case) and a tool description that tells the LLM when to call it.
3
Define Input Schema
Write the JSON Schema for the function's input parameters. This is what the LLM uses to construct tool call arguments.
4
Assign to Agent
In the agents-app, assign the AI Function to the target agent (or leave AgentId null for tenant-wide availability).
5
Test via Chat
Open a chat with the agent and trigger the function. Use the Context Inspector to verify the tool was called and the result injected.
AI Function vs. C# Tool: When to Use Each
| Scenario | Use AI Function | Use C# Tool |
|---|---|---|
| Data formatting / calculation | Yes — pure logic, no I/O needed | Overkill |
| Database query | No — no DB access in sandbox | Yes |
| External API call | No — no network in sandbox | Yes |
| Logic that admins may want to change | Yes — no deployment needed | No — requires developer |
| Complex multi-service orchestration | No — too complex for sandbox | Yes |