Skip to content
mcpkit-guide logo

MCPKit Guide

mcpkit-guide

Guide for using MCPKit Swift package to build MCP (Model Context Protocol) tool servers. Use when creating new MCP servers, defining tools, or integrating MCP into Swift projects.

SKILL.md

Full skill instructions

MCPKit Guide

This skill helps use the MCPKit Swift package to build MCP (Model Context Protocol) tool servers.

Package Overview

MCPKit is a Swift implementation of Model Context Protocol for building AI tool servers.

Installation

// Package.swift
dependencies: [
    .package(url: "https://github.com/​Sunalamye/​MCPKit.git", from: "1.0.0"),
]

targets: [
    .target(
        name: "YourApp",
        dependencies: ["MCPKit"]
    ),
]

Architecture

MCPKit/
├── Core/
│   ├── MCPTool.swift          - Protocol & Schema types
│   ├── MCPContext.swift       - Execution context
│   ├── MCPToolRegistry.swift  - Tool registration
│   └── MCPHandler.swift       - JSON-RPC handler
├── Transport/
│   └── MCPHTTPServer.swift    - HTTP server
└── Tools/
    └── BuiltInTools.swift     - Basic tools

Quick Start

1. Define a Tool

import MCPKit

struct MyTool: MCPTool {
    static let name = "my_tool"
    static let description = "Description for AI to understand when to use this tool"

    static let inputSchema = MCPInputSchema(
        properties: [
            "param1": .string("Parameter description"),
            "param2": .integer("Optional param description")
        ],
        required: ["param1"]
    )

    private let context: MCPContext

    init(context: MCPContext) {
        self.context = context
    }

    func execute(arguments: [String: Any]) async throws -> Any {
        guard let param1 = arguments["param1"] as? String else {
            throw MCPToolError.missingParameter("param1")
        }

        // Your logic here...

        return ["success": true, "result": "..."]
    }
}

2. Create Context

class MyContext: MCPContext {
    var serverPort: Int = 8080

    func executeJavaScript(_ script: String) async throws -> Any? {
        return nil
    }

    func getBotStatus() -> [String: Any]? {
        return ["status": "ready"]
    }

    func triggerAutoPlay() {}

    func getLogs() -> [[String: Any]] { logs }
    func clearLogs() { logs.removeAll() }
    func log(_ message: String) {
        logs.append(["message": message, "timestamp": Date()])
    }

    private var logs: [[String: Any]] = []
}

3. Register Tools & Start Server

import MCPKit

let context = MyContext()
let registry = MCPToolRegistry.shared

// Register built-in tools
registry.registerBuiltInTools(context: context)

// Register custom tools
registry.register(MyTool.self, context: context)

// Start HTTP server
let server = MCPHTTPServer(port: 8765, context: context)
try await server.start()

Input Schema Types

// No parameters
static let inputSchema = MCPInputSchema.empty

// With parameters
static let inputSchema = MCPInputSchema(
    properties: [
        "stringParam": .string("String parameter"),
        "intParam": .integer("Integer parameter"),
        "numberParam": .number("Number parameter"),
        "boolParam": .boolean("Boolean parameter"),
        "objectParam": .object("Object parameter")
    ],
    required: ["stringParam"]
)

Error Handling

throw MCPToolError.missingParameter("paramName")
throw MCPToolError.invalidParameter("paramName", expected: "string")
throw MCPToolError.executionFailed("Reason")
throw MCPToolError.notAvailable("Resource name")

Built-in Tools

ToolDescription
get_statusGet MCP server status
get_helpGet API documentation
get_logsGet debug logs
clear_logsClear all logs

JSON-RPC Methods

// Initialize
{"jsonrpc": "2.0", "method": "initialize", "id": 1}

// List tools
{"jsonrpc": "2.0", "method": "tools/​list", "id": 2}

// Call tool
{
  "jsonrpc": "2.0",
  "method": "tools/​call",
  "params": {"name": "my_tool", "arguments": {"param1": "value"}},
  "id": 3
}

Checklist for New Tools

  • Unique name (snake_case format)
  • Clear description (helps AI understand usage)
  • Correct inputSchema definition
  • Implement execute() method (async throws)
  • Handle errors with MCPToolError
  • Register in registry

Reference Documentation

More skills from majiayu000

xiaohongshu logo
majiayu000/claude-arsenal

xiaohongshu

xiaohongshu

286 148
View
agent-task-conductor logo
majiayu000/claude-skill-registry

agent-task-conductor

Conduct multi-agent task orchestration and workflow coordination.

663 1
View
conductor-setup logo
majiayu000/claude-skill-registry

conductor-setup

Initialize project with Conductor artifacts (product definition,

663 1
View
animation-designer logo
majiayu000/claude-skill-registry

animation-designer

Expert in web animations, transitions, and motion design using Framer Motion and CSS

663 1
View
diagramming logo
majiayu000/claude-skill-registry

diagramming

Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...

663 1
View
h3-pg logo
majiayu000/claude-skill-registry-data

h3-pg

PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.

23 1
View
conductor-development logo
majiayu000/claude-skill-registry

conductor-development

Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...

663 1
View
conductor-status logo
majiayu000/claude-skill-registry

conductor-status

Display project status, active tracks, and next actions

663 1
View
dockerization logo
majiayu000/claude-skill-registry

dockerization

Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.

663 1
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View