-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
90 changed files
with
4,867 additions
and
2,610 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import Foundation | ||
import JSONSchemaBuilder | ||
import MCPServer | ||
|
||
let transport = Transport.stdio() | ||
func proxy(_ transport: Transport) -> Transport { | ||
var sendToDataSequence: AsyncStream<Data>.Continuation? | ||
let dataSequence = AsyncStream<Data>.init { continuation in | ||
sendToDataSequence = continuation | ||
} | ||
|
||
Task { | ||
for await data in transport.dataSequence { | ||
mcpLogger.info("Reading data from transport: \(String(data: data, encoding: .utf8)!, privacy: .public)") | ||
sendToDataSequence?.yield(data) | ||
} | ||
} | ||
|
||
return Transport( | ||
writeHandler: { data in | ||
mcpLogger.info("Writing data to transport: \(String(data: data, encoding: .utf8)!, privacy: .public)") | ||
try await transport.writeHandler(data) | ||
}, | ||
dataSequence: dataSequence) | ||
} | ||
|
||
// MARK: - RepeatToolInput | ||
|
||
@Schemable | ||
struct RepeatToolInput { | ||
let text: String | ||
} | ||
|
||
let server = try await MCPServer( | ||
info: Implementation(name: "test-server", version: "1.0.0"), | ||
capabilities: ServerCapabilityHandlers(tools: [ | ||
Tool(name: "repeat") { (input: RepeatToolInput) in | ||
[.text(.init(text: input.text))] | ||
}, | ||
]), | ||
transport: proxy(transport)) | ||
|
||
try await server.waitForDisconnection() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/zsh | ||
|
||
dir=$(dirname "$0") | ||
(cd "$dir/.." && swift run ExampleMCPServer -q) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Inspect the server in the debugger: | ||
|
||
``` | ||
nvm use 20.18.1 | ||
npx @modelcontextprotocol/inspector "$(pwd)/ExampleMCPServer/launch.sh" | ||
``` | ||
|
||
|
||
# Observe console logs: | ||
- in Console.app, filter by `com.app.mcp` as the subsystem. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.