RAM2118 commited on
Commit
95438a2
·
verified ·
1 Parent(s): 8ef64a9

Sprint 7: McpServer.cpp — use param callbacks with Helper IPC fallback

Browse files
Files changed (1) hide show
  1. Source/Plugin/McpServer.cpp +49 -25
Source/Plugin/McpServer.cpp CHANGED
@@ -2,6 +2,7 @@
2
  #include "HelperConnection.h"
3
  #include "InstanceRegistry.h"
4
  #include "IPCProtocol.h"
 
5
 
6
  #define CPPHTTPLIB_THREAD_POOL_COUNT 2
7
  #include "httplib.h"
@@ -69,12 +70,7 @@ void McpServer::start()
69
  if (running.load()) return;
70
  serverThread = std::thread([this]() {
71
  running.store(true);
72
- // Try port 16620 first (Claude Code MCP registration). If taken by
73
- // another instance, fall back to OS-assigned port.
74
- if (server->bind_to_port("127.0.0.1", 16620))
75
- port = 16620;
76
- else
77
- port = server->bind_to_any_port("127.0.0.1");
78
  server->listen_after_bind();
79
  running.store(false);
80
  });
@@ -107,9 +103,9 @@ std::string McpServer::handleToolsList(const std::string& requestBody)
107
  {"result",{{"tools",json::array({
108
  {{"name","list_plugins"},{"description","Show loaded plugin info"},{"inputSchema",{{"type","object"},{"properties",json::object()}}}},
109
  {{"name","list_instances"},{"description","List all PluginBridge instances in DAW (channel names + ports)"},{"inputSchema",{{"type","object"},{"properties",json::object()}}}},
110
- {{"name","search_param"},{"description","Search params by keyword"},{"inputSchema",{{"type","object"},{"properties",{{"keyword",{{"type","string"}}}}},{"required",json::array({"keyword"})}}}},
111
  {{"name","get_params"},{"description","Get param values by index"},{"inputSchema",{{"type","object"},{"properties",{{"ids",{{"type","array"},{"items",{{"type","integer"}}}}}}},{"required",json::array({"ids"})}}}},
112
- {{"name","set_params"},{"description","Set params (batch, 0.0-1.0)"},{"inputSchema",{{"type","object"},{"properties",{{"values",{{"type","object"}}}}},{"required",json::array({"values"})}}}},
113
  {{"name","get_analysis"},{"description","Real-time audio analysis: LUFS, true peak, 7-band balance, stereo width, brightness. Prefixed with channel name."},{"inputSchema",{{"type","object"},{"properties",json::object()}}}}
114
  })}}}};
115
  return response.dump();
@@ -140,31 +136,59 @@ std::string McpServer::handleToolsCall(const std::string& requestBody)
140
  {"helper", helper.isHelperRunning() ? "connected" : "disconnected"}};
141
  resultText = info.dump();
142
  }
143
- else if (!helper.isHelperRunning())
144
- {
145
- resultText = "helper not connected";
146
- isError = true;
147
- }
148
  else if (toolName == "search_param")
149
  {
150
- json cmd = {{"cmd","search_param"},{"keyword",args.value("keyword","")}};
151
- auto resp = helper.sendCommand(cmd.dump());
152
- try { auto j = json::parse(resp); resultText = j.value("ok",false) ? j["results"].dump() : "search failed"; }
153
- catch (...) { resultText = "parse error"; isError = true; }
 
 
 
 
 
 
 
 
154
  }
155
  else if (toolName == "get_params")
156
  {
157
- json cmd = {{"cmd","get_params"},{"ids",args.value("ids",json::array())}};
158
- auto resp = helper.sendCommand(cmd.dump());
159
- try { auto j = json::parse(resp); resultText = j.value("ok",false) ? j["values"].dump() : "get failed"; }
160
- catch (...) { resultText = "parse error"; isError = true; }
 
 
 
 
 
 
 
 
 
 
 
161
  }
162
  else if (toolName == "set_params")
163
  {
164
- json cmd = {{"cmd","set_params"},{"values",args.value("values",json::object())}};
165
- auto resp = helper.sendCommand(cmd.dump());
166
- try { auto j = json::parse(resp); resultText = j.value("ok",false) ? "ok" : "set failed"; }
167
- catch (...) { resultText = "parse error"; isError = true; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  }
169
  else if (toolName == "get_analysis")
170
  {
 
2
  #include "HelperConnection.h"
3
  #include "InstanceRegistry.h"
4
  #include "IPCProtocol.h"
5
+ #include "Constants.h"
6
 
7
  #define CPPHTTPLIB_THREAD_POOL_COUNT 2
8
  #include "httplib.h"
 
70
  if (running.load()) return;
71
  serverThread = std::thread([this]() {
72
  running.store(true);
73
+ port = server->bind_to_any_port("127.0.0.1");
 
 
 
 
 
74
  server->listen_after_bind();
75
  running.store(false);
76
  });
 
103
  {"result",{{"tools",json::array({
104
  {{"name","list_plugins"},{"description","Show loaded plugin info"},{"inputSchema",{{"type","object"},{"properties",json::object()}}}},
105
  {{"name","list_instances"},{"description","List all PluginBridge instances in DAW (channel names + ports)"},{"inputSchema",{{"type","object"},{"properties",json::object()}}}},
106
+ {{"name","search_param"},{"description","Search params by keyword. Returns index 'i' and current value. Use 'i' as key for set_params/get_params."},{"inputSchema",{{"type","object"},{"properties",{{"keyword",{{"type","string"}}}}},{"required",json::array({"keyword"})}}}},
107
  {{"name","get_params"},{"description","Get param values by index"},{"inputSchema",{{"type","object"},{"properties",{{"ids",{{"type","array"},{"items",{{"type","integer"}}}}}}},{"required",json::array({"ids"})}}}},
108
+ {{"name","set_params"},{"description","Set params (batch, 0.0-1.0). Keys are param index from search_param."},{"inputSchema",{{"type","object"},{"properties",{{"values",{{"type","object"}}}}},{"required",json::array({"values"})}}}},
109
  {{"name","get_analysis"},{"description","Real-time audio analysis: LUFS, true peak, 7-band balance, stereo width, brightness. Prefixed with channel name."},{"inputSchema",{{"type","object"},{"properties",json::object()}}}}
110
  })}}}};
111
  return response.dump();
 
136
  {"helper", helper.isHelperRunning() ? "connected" : "disconnected"}};
137
  resultText = info.dump();
138
  }
 
 
 
 
 
139
  else if (toolName == "search_param")
140
  {
141
+ if (searchParamCallback)
142
+ {
143
+ resultText = searchParamCallback(args.value("keyword", ""));
144
+ }
145
+ else if (helper.isHelperRunning())
146
+ {
147
+ json cmd = {{"cmd","search_param"},{"keyword",args.value("keyword","")}};
148
+ auto resp = helper.sendCommand(cmd.dump());
149
+ try { auto j = json::parse(resp); resultText = j.value("ok",false) ? j["results"].dump() : "search failed"; }
150
+ catch (...) { resultText = "parse error"; isError = true; }
151
+ }
152
+ else { resultText = "no plugin loaded"; isError = true; }
153
  }
154
  else if (toolName == "get_params")
155
  {
156
+ if (getParamsCallback)
157
+ {
158
+ auto idsJson = args.value("ids", json::array());
159
+ std::vector<int> ids;
160
+ for (auto& v : idsJson) ids.push_back(v.get<int>());
161
+ resultText = getParamsCallback(ids);
162
+ }
163
+ else if (helper.isHelperRunning())
164
+ {
165
+ json cmd = {{"cmd","get_params"},{"ids",args.value("ids",json::array())}};
166
+ auto resp = helper.sendCommand(cmd.dump());
167
+ try { auto j = json::parse(resp); resultText = j.value("ok",false) ? j["values"].dump() : "get failed"; }
168
+ catch (...) { resultText = "parse error"; isError = true; }
169
+ }
170
+ else { resultText = "no plugin loaded"; isError = true; }
171
  }
172
  else if (toolName == "set_params")
173
  {
174
+ if (setParamsCallback)
175
+ {
176
+ auto valuesJson = args.value("values", json::object());
177
+ std::map<int,float> values;
178
+ for (auto& [k, v] : valuesJson.items())
179
+ values[std::stoi(k)] = v.get<float>();
180
+ bool ok = setParamsCallback(values);
181
+ resultText = ok ? "ok" : "set failed";
182
+ if (!ok) isError = true;
183
+ }
184
+ else if (helper.isHelperRunning())
185
+ {
186
+ json cmd = {{"cmd","set_params"},{"values",args.value("values",json::object())}};
187
+ auto resp = helper.sendCommand(cmd.dump());
188
+ try { auto j = json::parse(resp); resultText = j.value("ok",false) ? "ok" : "set failed"; }
189
+ catch (...) { resultText = "parse error"; isError = true; }
190
+ }
191
+ else { resultText = "no plugin loaded"; isError = true; }
192
  }
193
  else if (toolName == "get_analysis")
194
  {