Resources provide read-only data to AI assistants. Unlike tools (which perform actions), resources simply expose information — configuration files, database records, logs, documentation, or any other data your application manages.
await mcp.registerResource( PrismMCPResource( uri: "db://schema", name: "Database Schema", description: "All tables and columns in the database" ), handler: { let tables = try await db.query( "SELECT name FROM sqlite_master WHERE type='table'" ) var output = "" for table in tables { let name = table["name"] output += "\n## \(name)\n" let cols = try await db.query("PRAGMA table_info(\(name))") for col in cols { output += " - \(col["name"]) (\(col["type"]))\n" } } return output })
Log Files
await mcp.registerResource( PrismMCPResource( uri: "log://app/latest", name: "Recent Logs", description: "Last 100 lines of application logs" ), handler: { let logPath = "/var/log/myapp/app.log" let content = try String(contentsOfFile: logPath, encoding: .utf8) let lines = content.split(separator: "\n").suffix(100) return lines.joined(separator: "\n") })
API Documentation
await mcp.registerResource( PrismMCPResource( uri: "docs://api", name: "API Documentation", description: "REST API endpoints and their descriptions", mimeType: "text/markdown" ), handler: { """ # API Endpoints ## Users - GET /api/users - List all users - POST /api/users - Create a user - GET /api/users/:id - Get user by ID ## Posts - GET /api/posts - List all posts - POST /api/posts - Create a post """ })