Skip to content

Commit feaf981

Browse files
committed
get basic docc stuff going
1 parent 0ca76df commit feaf981

17 files changed

+389
-6
lines changed

Sources/SwiftMCP/Models/Tools/ToolCallResponse.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Foundation
22

33
/// Response structure for tool calls
4-
struct ToolCallResponse: Codable {
4+
public struct ToolCallResponse: Codable {
55
var jsonrpc: String = "2.0"
66
let id: Int
77
let result: Result
@@ -28,7 +28,7 @@ struct ToolCallResponse: Codable {
2828
}
2929

3030
extension ToolCallResponse {
31-
init(id: Int, error: Error)
31+
public init(id: Int, error: Error)
3232
{
3333
self.id = id
3434
self.result = Result(
@@ -37,7 +37,7 @@ extension ToolCallResponse {
3737
)
3838
}
3939

40-
init(id: Int, result: String)
40+
public init(id: Int, result: String)
4141
{
4242
self.id = id
4343
self.result = Result(
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Getting Started with SwiftMCP
2+
3+
Create your first MCP server in minutes.
4+
5+
## Overview
6+
7+
SwiftMCP makes it easy to build Model Control Protocol (MCP) servers that can interact with AI models. This guide will help you get started with the basics.
8+
9+
## Installation
10+
11+
Add SwiftMCP to your project using Swift Package Manager:
12+
13+
```swift
14+
dependencies: [
15+
.package(url: "https://github.com/yourusername/SwiftMCP.git", from: "1.0.0")
16+
]
17+
```
18+
19+
## Basic Usage
20+
21+
1. Create a new Swift file for your server:
22+
23+
```swift
24+
import SwiftMCP
25+
26+
@MCPServer(version: "1.0.0")
27+
struct Calculator {
28+
@MCPTool(description: "Adds two numbers together")
29+
func add(a: Double, b: Double) -> Double {
30+
return a + b
31+
}
32+
}
33+
```
34+
35+
2. Run your server:
36+
37+
```swift
38+
import SwiftMCP
39+
40+
let calculator = Calculator()
41+
let transport = StdioTransport()
42+
43+
try await transport.start(server: calculator)
44+
```
45+
46+
## Next Steps
47+
48+
- Follow the <doc:BuildingAnMCPServer> tutorial to learn more advanced features
49+
- Explore the API documentation for detailed information about available options
50+
- Check out the example projects in the repository
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
A Calculator for simple math operations like addition, subtraction, and more.
3+
*/
4+
class Calculator {
5+
/**
6+
Adds two numbers together and returns their sum.
7+
8+
- Parameter a: First number to add
9+
- Parameter b: Second number to add
10+
- Returns: The sum of a and b
11+
*/
12+
func add(a: Double, b: Double) -> Double {
13+
return a + b
14+
}
15+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import SwiftMCP
2+
3+
/**
4+
A Calculator for simple math operations like addition, subtraction, and more.
5+
*/
6+
@MCPServer(version: "1.0.0")
7+
class Calculator {
8+
/**
9+
Adds two numbers together and returns their sum.
10+
11+
- Parameter a: First number to add
12+
- Parameter b: Second number to add
13+
- Returns: The sum of a and b
14+
*/
15+
func add(a: Double, b: Double) -> Double {
16+
return a + b
17+
}
18+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import SwiftMCP
2+
3+
/**
4+
A Calculator for simple math operations like addition, subtraction, and more.
5+
*/
6+
@MCPServer(version: "1.0.0")
7+
class Calculator {
8+
/**
9+
Adds two numbers together and returns their sum.
10+
11+
- Parameter a: First number to add
12+
- Parameter b: Second number to add
13+
- Returns: The sum of a and b
14+
*/
15+
@MCPTool
16+
func add(a: Double, b: Double) -> Double {
17+
return a + b
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import SwiftMCP
2+
3+
/**
4+
A Calculator for simple math operations like addition, subtraction, and more.
5+
*/
6+
@MCPServer(version: "1.0.0", name: "SwiftMCP Demo")
7+
class Calculator {
8+
/**
9+
Adds two numbers together and returns their sum.
10+
11+
- Parameter a: First number to add
12+
- Parameter b: Second number to add
13+
- Returns: The sum of a and b
14+
*/
15+
@MCPTool
16+
func add(a: Double, b: Double) -> Double {
17+
return a + b
18+
}
19+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
A custom error type for handling validation errors in the MCP server.
3+
*/
4+
import Foundation
5+
6+
enum GreetingError: LocalizedError {
7+
case nameTooShort
8+
9+
var errorDescription: String? {
10+
switch self {
11+
case .nameTooShort:
12+
return "Name must be at least 2 characters long"
13+
}
14+
}
15+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import SwiftMCP
2+
3+
/**
4+
A Calculator for simple math operations like addition, subtraction, and more.
5+
*/
6+
@MCPServer(version: "1.0.0", name: "SwiftMCP Demo")
7+
class Calculator {
8+
/**
9+
Adds two numbers together and returns their sum.
10+
11+
- Parameter a: First number to add
12+
- Parameter b: Second number to add
13+
- Returns: The sum of a and b
14+
*/
15+
@MCPTool(description: "Performs addition of two numbers")
16+
func add(a: Double, b: Double) -> Double {
17+
return a + b
18+
}
19+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import SwiftMCP
2+
3+
@MCPServer(version: "1.0.0")
4+
struct Calculator {
5+
@MCPTool(description: "Adds two numbers together")
6+
func add(a: Double, b: Double) -> Double {
7+
return a + b
8+
}
9+
10+
@MCPTool(description: "Greets a person by name")
11+
func greet(name: String) throws -> String {
12+
guard name.count >= 2 else {
13+
throw GreetingError.nameTooShort
14+
}
15+
return "Hello, \(name)!"
16+
}
17+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import SwiftMCP
2+
3+
@MCPServer(version: "1.0.0")
4+
struct Calculator {
5+
@MCPTool(description: "Adds two numbers together")
6+
func add(a: Double, b: Double) -> Double {
7+
return a + b
8+
}
9+
10+
@MCPTool(description: "Greets a person by name")
11+
func greet(name: String) throws -> String {
12+
guard name.count >= 2 else {
13+
throw GreetingError.nameTooShort
14+
}
15+
return "Hello, \(name)!"
16+
}
17+
18+
@MCPTool(description: "Sends a delayed greeting")
19+
func delayedGreet(name: String) async throws -> String {
20+
try await Task.sleep(for: .seconds(1))
21+
return try greet(name: name)
22+
}
23+
}

0 commit comments

Comments
 (0)