A template repository providing a barebones foundation for building Model Control Protocol (MCP) servers for macOS applications and command line tools.
MCP Template serves as a starting point for developers looking to implement MCP servers in their projects. This template demonstrates how to use the mcp-swift-sdk
in a minimal way, making it easier to understand the basics of MCP integration. It includes both a library template for integration into other projects and a simple command-line example to illustrate basic usage.
This repository is intended to be:
mcp-swift-sdk
Current and planned features include:
run
commandAdd the following to your Package.swift
file:
dependencies: [
.package(url: "https://github.com/your-username/mcp-template.git", branch: "main"),
]
Then add the dependency to your target:
.target(
name: "YourTarget",
dependencies: [
.product(name: "EasyMCP", package: "mcp-template")
]
),
import EasyMCP
// Create an instance of EasyMCP
let mcp = EasyMCP()
// Register a tool
try await mcp.register(tool: Tool(
name: "helloPerson",
description: "Returns a friendly greeting message",
inputSchema: [
"type": "object",
"properties": [
"name": [
"type": "string",
"description": "Name of the person to say hello to",
]
],
"required": ["name"]
]
)) { input in
// It's an async closure, so you can await whatever you need to for long running tasks
await someOtherAsyncStuffIfYouWant()
// Return your result and flag if it is/not an error
return Result(content: [.text(hello(input["name"]?.stringValue ?? "world"))], isError: false)
}
// Start the MCP server for full MCP interaction
try await mcp.start()
try await mcp.waitUntilComplete()
The package includes a command line executable called mcpexample
that demonstrates basic usage:
# Run the basic hello example
mcpexample hello
# Start the MCP server to handle MCP protocol communications
mcpexample run
mcp-swift-sdk
ArgumentParser
for CLI argument handlingTo use this template for your own MCP server:
shell
swift build
shell
swift test
To test and debug your MCP server using the MCP Inspector:
shell
npx @modelcontextprotocol/inspector <absolute_path_to_your_executable> run
🔍 MCP Inspector is up and running at http://localhost:5173 🚀
tail -n 20 -f ~/Library/Logs/Claude/mcp*.log
This setup provides a powerful debugging environment where you can:
For more debugging tips, visit MCP Debugging at Anthropic's modelcontextprotocol.io site.
MIT licensed.
A barebones MCP server implementation in Swift using loopwork-ai's mcp-swift-sdk.