External functions that execute on the server side of applications
Core Idea: Server tools are functions defined and executed on server environments that LLMs can invoke through function/tool calling mechanisms, enabling AI to access external data sources, APIs, and perform actions outside its knowledge context.
Key Elements
Characteristics
- Execute on the server rather than in the client environment
- Have access to server-side resources, databases, and APIs
- Can perform privileged operations not possible from client code
- Results are returned to the LLM for further reasoning and response generation
Implementation Approaches
- Direct Implementation
- Define tools directly in server code
- Execute within the same process as the main application
- Access server resources without additional authentication
// Tool defined directly in server code const getProducts = tool({ name: "getProducts", description: "Get all the products from the database", parameters: z.object({}), // No parameters needed execute: async () => { return await fetchGuitars(); // Server-side function } });
2. **MCP Server Implementation**
- Define tools in separate MCP server
- Connect main server to MCP server
- Execute tools in isolated process with focused responsibilities
```javascript
// MCP server tool definition
server.addTool('getInventory', {
description: 'Get the product inventory',
parameters: {}, // No parameters
execute: async () => {
return JSON.stringify(await fetchInventory());
}
});
```
### Tool Registration Process
1. Define tool name, description, and parameter schema
2. Implement execute function that performs the actual work
3. Register tool with the system (direct or via MCP client)
4. Make available to the LLM via appropriate configuration
### Execution Flow
1. LLM determines a tool is needed based on user query
2. LLM requests a tool call with appropriate parameters
3. Server intercepts tool call request
4. Server executes the tool with provided parameters
5. Results are returned to the LLM for incorporation in response
6. LLM generates final user-facing response using tool results
### Common Server Tool Types
- **Data Access Tools**: Connect to databases or data stores
- **API Clients**: Make requests to external services
- **Processing Tools**: Perform server-side computation
- **System Tools**: Interact with server filesystem or environment
- **Integration Tools**: Connect to enterprise systems
### Best Practices
- Keep tools focused on single responsibilities
- Provide clear descriptions to help LLM understand when to use them
- Validate and sanitize inputs to prevent security issues
- Handle errors gracefully with informative messages
- Use parameter schemas to enforce correct input formats
- Add appropriate logging for debugging and monitoring
## Additional Connections
- **Broader Context**: Function Calling (mechanism enabling tool use)
- **Applications**: MCP Server Implementation (specialized server for tool hosting)
- **See Also**: Client Tools (tools that execute in client environments), Tool Call Flow (process of tool execution)
## References
1. Blue Collar Coder video on Model Context Protocol implementation
2. Vercel AI documentation for tool definitions
3. Model Context Protocol specification
#server-tools #tool-calling #ai-tools #server-side-execution #function-calling
---
**Connections:**
-
---
**Sources:**
- From: Jack Herrington - Applied Model Context Protocol (MCP) In 20 Minutes