Extend the AI's capabilities with external tools using the Model Context Protocol.
Give the AI access to your filesystem.
Map<String, Object> server = Map.of( "type", "local", "command", "npx", "args", List.of("-y", "@modelcontextprotocol/server-filesystem", "/tmp"), "tools", List.of("*") ); var session = client.createSession( new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL) .setMcpServers(Map.of("filesystem", server)) ).get(); var result = session.sendAndWait("List files in the directory").get(); System.out.println(result.getData().content());Tip: Browse the MCP Servers Directory for community servers like GitHub, SQLite, and Puppeteer.
Run a tool as a subprocess (stdin/stdout communication).
var server = new HashMap<String, Object>(); server.put("type", "local"); server.put("command", "node"); server.put("args", List.of("./mcp-server.js")); server.put("env", Map.of("DEBUG", "true")); server.put("cwd", "./servers"); server.put("tools", List.of("*"));| command | Executable to run |
| args | Command-line arguments |
| env | Environment variables |
| cwd | Working directory |
| tools | ["*"] for all, [] for none, or specific tool names |
| timeout | Timeout in milliseconds |
Connect to a cloud-hosted MCP server via HTTP.
Map<String, Object> server = Map.of( "type", "http", "url", "https://api.githubcopilot.com/mcp/", "headers", Map.of("Authorization", "Bearer " + token), "tools", List.of("*") );| type | "http" or "sse" |
| url | Server endpoint |
| headers | HTTP headers for authentication |
| tools | Tools to enable |
| timeout | Timeout in milliseconds |
Combine tools from several sources.
var session = client.createSession( new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL) .setMcpServers(Map.of( "filesystem", filesystemServer, "github", githubServer, "database", sqliteServer )) ).get();| Tools not invoked | Set tools to ["*"] or list specific tool names |
| Server not found | Verify command path is correct and executable |
| Connection refused | Check URL and authentication headers |
| Timeout errors | Increase timeout or check server performance |
Debug tips:
© 2026