minimal-server.vala 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Minimal MCP Server Example
  3. *
  4. * This example demonstrates the simplest possible MCP server implementation.
  5. * It creates a server with basic capabilities and no custom resources, tools, or prompts.
  6. *
  7. * Compile with:
  8. * valac --pkg mcp-vala --pkg json-glib-1.0 --pkg gee-0.8 minimal-server.vala -o minimal-server
  9. */
  10. using Mcp;
  11. using Posix;
  12. int main (string[] args) {
  13. // Create server information
  14. // This identifies your server to MCP clients
  15. var server_info = new Mcp.Types.Protocol.ServerInfo (
  16. "minimal-server", // Server name
  17. "1.0.0" // Version
  18. );
  19. server_info.description = "A minimal MCP server example";
  20. // Create server capabilities
  21. // This tells clients what features your server supports
  22. var capabilities = new Mcp.Types.Protocol.ServerCapabilities ();
  23. // Enable logging capability
  24. capabilities.logging = true;
  25. // Create the server instance
  26. var server = new Mcp.Core.Server (server_info, capabilities);
  27. // Start the server asynchronously
  28. server.start.begin ((obj, res) => {
  29. try {
  30. bool started = server.start.end (res);
  31. if (started) {
  32. // Server started successfully
  33. // Waiting for MCP client connections...
  34. } else {
  35. // Failed to start server
  36. }
  37. } catch (Error e) {
  38. // Error handling
  39. }
  40. });
  41. // Create a main loop to keep the application running
  42. var loop = new MainLoop ();
  43. // Connect shutdown signal to quit the loop
  44. server.shutdown.connect (() => {
  45. printerr ("Server shutting down...\n");
  46. loop.quit ();
  47. });
  48. // Handle Ctrl+C to gracefully shutdown
  49. // Note: signal handling requires the --pkg posix flag when compiling
  50. // For now, we'll skip signal handling to get the build working
  51. // Run the main loop
  52. loop.run ();
  53. printerr ("Server stopped\n");
  54. return 0;
  55. }