| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- /*
- * Minimal MCP Server Example
- *
- * This example demonstrates the simplest possible MCP server implementation.
- * It creates a server with basic capabilities and no custom resources, tools, or prompts.
- *
- * Compile with:
- * valac --pkg mcp-vala --pkg json-glib-1.0 --pkg gee-0.8 minimal-server.vala -o minimal-server
- */
- using Mcp;
- using Posix;
- int main (string[] args) {
- // Create server information
- // This identifies your server to MCP clients
- var server_info = new Mcp.Types.Protocol.ServerInfo (
- "minimal-server", // Server name
- "1.0.0" // Version
- );
- server_info.description = "A minimal MCP server example";
-
- // Create server capabilities
- // This tells clients what features your server supports
- var capabilities = new Mcp.Types.Protocol.ServerCapabilities ();
-
- // Enable logging capability
- capabilities.logging = true;
-
- // Create the server instance
- var server = new Mcp.Core.Server (server_info, capabilities);
-
- // Start the server asynchronously
- server.start.begin ((obj, res) => {
- try {
- bool started = server.start.end (res);
- if (started) {
- // Server started successfully
- // Waiting for MCP client connections...
- } else {
- // Failed to start server
- }
- } catch (Error e) {
- // Error handling
- }
- });
-
- // Create a main loop to keep the application running
- var loop = new MainLoop ();
-
- // Connect shutdown signal to quit the loop
- server.shutdown.connect (() => {
- printerr ("Server shutting down...\n");
- loop.quit ();
- });
-
- // Handle Ctrl+C to gracefully shutdown
- // Note: signal handling requires the --pkg posix flag when compiling
- // For now, we'll skip signal handling to get the build working
-
- // Run the main loop
- loop.run ();
-
- printerr ("Server stopped\n");
- return 0;
- }
|