This commit is contained in:
39
docs/snippets/swift/mcp/mcp_custom_client.md
Normal file
39
docs/snippets/swift/mcp/mcp_custom_client.md
Normal file
@@ -0,0 +1,39 @@
|
||||
<!-- snippet:syntax-only -->
|
||||
|
||||
```swift title="Swift"
|
||||
import Foundation
|
||||
|
||||
let process = Process()
|
||||
process.executableURL = URL(fileURLWithPath: "/usr/bin/env")
|
||||
process.arguments = ["kreuzberg", "mcp"]
|
||||
|
||||
let stdin = Pipe()
|
||||
let stdout = Pipe()
|
||||
process.standardInput = stdin
|
||||
process.standardOutput = stdout
|
||||
|
||||
try process.run()
|
||||
|
||||
let request: [String: Any] = [
|
||||
"method": "tools/call",
|
||||
"params": [
|
||||
"name": "extract_file",
|
||||
"arguments": [
|
||||
"path": "document.pdf",
|
||||
"async": true,
|
||||
],
|
||||
],
|
||||
]
|
||||
|
||||
let payload = try JSONSerialization.data(withJSONObject: request)
|
||||
stdin.fileHandleForWriting.write(payload)
|
||||
stdin.fileHandleForWriting.write("\n".data(using: .utf8)!)
|
||||
try stdin.fileHandleForWriting.close()
|
||||
|
||||
let data = stdout.fileHandleForReading.availableData
|
||||
if let line = String(data: data, encoding: .utf8) {
|
||||
print(line)
|
||||
}
|
||||
|
||||
process.waitUntilExit()
|
||||
```
|
||||
Reference in New Issue
Block a user