Swift-Mcp-Server-Generator
Swift-Mcp-Server-Generator是一款code方向的AI技能,核心价值是Generate a complete Model Context Protocol server project in Swift using the official MCP Swift SDK package,可用于解决开发者在code领域的实际问题,帮助用户提升效率、自动化重复任务或优化工作流。
Generate a complete Model Context Protocol server project in Swift using the official MCP Swift SDK package.
mkdir -p ./skills/swift-mcp-server-generator && curl -sfL https://raw.githubusercontent.com/github/awesome-copilot/main/skills/swift-mcp-server-generator/SKILL.md -o ./skills/swift-mcp-server-generator/SKILL.md Run in terminal / PowerShell. Requires curl (Unix) or PowerShell 5+ (Windows).
Skill Content
# Swift MCP Server Generator
Generate a complete, production-ready MCP server in Swift using the official Swift SDK package.
Project Generation
When asked to create a Swift MCP server, generate a complete project with this structure:
my-mcp-server/
├── Package.swift
├── Sources/
│ └── MyMCPServer/
│ ├── main.swift
│ ├── Server.swift
│ ├── Tools/
│ │ ├── ToolDefinitions.swift
│ │ └── ToolHandlers.swift
│ ├── Resources/
│ │ ├── ResourceDefinitions.swift
│ │ └── ResourceHandlers.swift
│ └── Prompts/
│ ├── PromptDefinitions.swift
│ └── PromptHandlers.swift
├── Tests/
│ └── MyMCPServerTests/
│ └── ServerTests.swift
└── README.mdPackage.swift Template
// swift-tools-version: 6.0
import PackageDescription
let package = Package(
name: "MyMCPServer",
platforms: [
.macOS(.v13),
.iOS(.v16),
.watchOS(.v9),
.tvOS(.v16),
.visionOS(.v1)
],
dependencies: [
.package(
url: "https://github.com/modelcontextprotocol/swift-sdk.git",
from: "0.10.0"
),
.package(
url: "https://github.com/apple/swift-log.git",
from: "1.5.0"
),
.package(
url: "https://github.com/swift-server/swift-service-lifecycle.git",
from: "2.0.0"
)
],
targets: [
.executableTarget(
name: "MyMCPServer",
dependencies: [
.product(name: "MCP", package: "swift-sdk"),
.product(name: "Logging", package: "swift-log"),
.product(name: "ServiceLifecycle", package: "swift-service-lifecycle")
]
),
.testTarget(
name: "MyMCPServerTests",
dependencies: ["MyMCPServer"]
)
]
)main.swift Template
import MCP
import Logging
import ServiceLifecycle
struct MCPService: Service {
let server: Server
let transport: Transport
func run() async throws {
try await server.start(transport: transport) { clientInfo, capabilities in
logger.info("Client connected", metadata: [
"name": .string(clientInfo.name),
"version": .string(clientInfo.version)
])
}
// Keep service running
try await Task.sleep(for: .days(365 * 100))
}
func shutdown() async throws {
logger.info("Shutting down MCP server")
await server.stop()
}
}
var logger = Logger(label: "com.example.mcp-server")
logger.logLevel = .info
do {
let server = await createServer()
let transport = StdioTransport(logger: logger)
let service = MCPService(server: server, transport: transport)
let serviceGroup = ServiceGroup(
services: [service],
configuration: .init(
gracefulShutdownSignals: [.sigterm, .sigint]
),
logger: logger
)
try await serviceGroup.run()
} catch {
logger.error("Fatal error", metadata: ["error": .string("\(error)")])
throw error
}Server.swift Template
import MCP
import Logging
func createServer() async -> Server {
let server = Server(
name: "MyMCPServer",
version: "1.0.0",
capabilities: .init(
prompts: .init(listChanged: true),
resources: .init(subscribe: true, listChanged: true),
tools: .init(listChanged: true)
)
)
// Register tool handlers
await registerToolHandlers(server: server)
// Register resource handlers
await registerResourceHandlers(server: server)
// Register prompt handlers
await registerPromptHandlers(server: server)
return server
}ToolDefinitions.swift Template
import MCP
func getToolDefinitions() -> [Tool] {
[
Tool(
name: "greet",
description: "Genera🎯 Best For
- Developers scaffolding new projects
- Prototype builders
- Claude users
- GitHub Copilot users
- Software engineers
💡 Use Cases
- Bootstrapping React components
- Creating API route handlers
- Code quality improvement
- Best practice enforcement
📖 How to Use This Skill
- 1
Install the Skill
Copy the install command from the Terminal tab and run it. The SKILL.md file downloads to your local skills directory.
- 2
Load into Your AI Assistant
Open Claude or GitHub Copilot and reference the skill. Paste the SKILL.md content or use the system prompt tab.
- 3
Apply Swift-Mcp-Server-Generator to Your Work
Open your project in the AI assistant and ask it to apply the skill. Start with a small module to verify the output quality.
- 4
Review and Refine
Review AI suggestions before committing. Run tests, check for regressions, and iterate on the skill output.
❓ Frequently Asked Questions
Can I customize the generated output?
Yes — modify the skill's prompt instructions to match your project conventions and coding style.
Is Swift-Mcp-Server-Generator compatible with Cursor and VS Code?
Yes — this skill works with any AI coding assistant including Cursor, VS Code with Copilot, and JetBrains IDEs.
Do I need specific dependencies for Swift-Mcp-Server-Generator?
Check the install command and Works With section. Most code skills only require the AI assistant and your codebase.
How do I install Swift-Mcp-Server-Generator?
Copy the install command from the Terminal tab and run it. The skill downloads to ./skills/swift-mcp-server-generator/SKILL.md, ready to use.
Can I customize this skill for my team?
Absolutely. Edit the SKILL.md file to add team-specific instructions, examples, or workflows.
⚠️ Common Mistakes to Avoid
Using generated code without understanding
Understand what generated code does before shipping it to production.
Skipping validation
Always test AI-generated code changes, even for simple refactors.
Missing dependency updates
Check if the skill requires updated dependencies or new packages.