@@ -779,6 +779,115 @@ TEST(error_with_data_preserves_id) {
779779 ASSERT (err.indexOf (" field_x" ) >= 0 );
780780}
781781
782+ // ════════════════════════════════════════════════════════════════════════
783+ // Instructions & Version Tests
784+ // ════════════════════════════════════════════════════════════════════════
785+
786+ TEST (instructions_included_in_initialize) {
787+ Server server (" test" , 80 );
788+ server.setInstructions (" Read temperature before adjusting fans." );
789+
790+ String res = server._processJsonRpc (
791+ R"( {"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-03-26","clientInfo":{"name":"test"}}})" );
792+ ASSERT (res.indexOf (" Read temperature before adjusting fans." ) >= 0 );
793+ ASSERT (res.indexOf (" \" instructions\" " ) >= 0 );
794+ }
795+
796+ TEST (instructions_absent_when_not_set) {
797+ Server server (" test" , 80 );
798+
799+ String res = server._processJsonRpc (
800+ R"( {"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-03-26","clientInfo":{"name":"test"}}})" );
801+ ASSERT (res.indexOf (" \" instructions\" " ) < 0 );
802+ }
803+
804+ TEST (custom_version_in_initialize) {
805+ Server server (" test" , 80 );
806+ server.setVersion (" 1.2.3-custom" );
807+
808+ String res = server._processJsonRpc (
809+ R"( {"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-03-26","clientInfo":{"name":"test"}}})" );
810+ ASSERT (res.indexOf (" 1.2.3-custom" ) >= 0 );
811+ }
812+
813+ TEST (default_version_when_not_overridden) {
814+ Server server (" test" , 80 );
815+
816+ String res = server._processJsonRpc (
817+ R"( {"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-03-26","clientInfo":{"name":"test"}}})" );
818+ ASSERT (res.indexOf (MCPD_VERSION) >= 0 );
819+ }
820+
821+ // ════════════════════════════════════════════════════════════════════════
822+ // Tool Enable/Disable Tests
823+ // ════════════════════════════════════════════════════════════════════════
824+
825+ TEST (disable_tool_hides_from_list) {
826+ Server server (" test" , 80 );
827+ server.addTool (" visible" , " A tool" , " {}" , [](const JsonObject&) { return String (" ok" ); });
828+ server.addTool (" hidden" , " Another" , " {}" , [](const JsonObject&) { return String (" ok" ); });
829+
830+ server._processJsonRpc (
831+ R"( {"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-03-26","clientInfo":{"name":"test"}}})" );
832+
833+ // Both visible initially
834+ String res = server._processJsonRpc (
835+ R"( {"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}})" );
836+ ASSERT (res.indexOf (" \" visible\" " ) >= 0 );
837+ ASSERT (res.indexOf (" \" hidden\" " ) >= 0 );
838+
839+ // Disable one
840+ ASSERT (server.disableTool (" hidden" ));
841+ res = server._processJsonRpc (
842+ R"( {"jsonrpc":"2.0","id":3,"method":"tools/list","params":{}})" );
843+ ASSERT (res.indexOf (" \" visible\" " ) >= 0 );
844+ ASSERT (res.indexOf (" \" hidden\" " ) < 0 );
845+ }
846+
847+ TEST (disabled_tool_cannot_be_called) {
848+ Server server (" test" , 80 );
849+ server.addTool (" mytool" , " A tool" , " {}" , [](const JsonObject&) { return String (" ok" ); });
850+
851+ server._processJsonRpc (
852+ R"( {"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-03-26","clientInfo":{"name":"test"}}})" );
853+
854+ server.disableTool (" mytool" );
855+ String res = server._processJsonRpc (
856+ R"( {"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"mytool","arguments":{}}})" );
857+ ASSERT (res.indexOf (" \" error\" " ) >= 0 );
858+ ASSERT (res.indexOf (" Tool not found" ) >= 0 );
859+ }
860+
861+ TEST (re_enable_tool_makes_it_visible) {
862+ Server server (" test" , 80 );
863+ server.addTool (" toggle" , " Togglable" , " {}" , [](const JsonObject&) { return String (" ok" ); });
864+
865+ server._processJsonRpc (
866+ R"( {"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-03-26","clientInfo":{"name":"test"}}})" );
867+
868+ server.disableTool (" toggle" );
869+ ASSERT (server.isToolEnabled (" toggle" ) == false );
870+
871+ server.enableTool (" toggle" );
872+ ASSERT (server.isToolEnabled (" toggle" ) == true );
873+
874+ String res = server._processJsonRpc (
875+ R"( {"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}})" );
876+ ASSERT (res.indexOf (" \" toggle\" " ) >= 0 );
877+ }
878+
879+ TEST (enable_nonexistent_tool_returns_false) {
880+ Server server (" test" , 80 );
881+ ASSERT (server.enableTool (" nonexistent" ) == false );
882+ ASSERT (server.disableTool (" nonexistent" ) == false );
883+ }
884+
885+ TEST (is_tool_enabled_default_true) {
886+ Server server (" test" , 80 );
887+ server.addTool (" mytool" , " test" , " {}" , [](const JsonObject&) { return String (" ok" ); });
888+ ASSERT (server.isToolEnabled (" mytool" ) == true );
889+ }
890+
782891// ════════════════════════════════════════════════════════════════════════
783892
784893int main () {
0 commit comments