Rótulo do bloco declarado pela library (tb_type_block_set_label)

A library diz como o bloco aparece no editor ("liste as ferramentas de
%1", valores iniciais "a|b"); o editor usa a tabela dele quando conhece
o tipo e o rótulo da library quando não conhece. Assim uma library
carregada de fora não aparece só com o nome técnico.

Acessibilidade: aviso comum não repete "aviso" na descrição.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mguinhosandClaude Opus 5.5 committed 2026-10-23 07:50:39 -03:00
1 parent 8f046833e7
commit 2d580005b1
4 files changed
+33 -112

No files matched your search

-109
View File
@@ -1,109 +0,0 @@
/*
* mcp.c - Plugin TinyBlocks com blocos MCP (Model Context Protocol).
*
* Blocos:
* MCP.Server - literal: armazena a URL do servidor MCP
* HTTP: "http://localhost:3000/mcp"
* stdio: "stdio://npx @modelcontextprotocol/server-filesystem /tmp"
*
* MCP.Ping - input: url (text) -> output: status (text)
* Verifica se o servidor responde.
*
* MCP.ListTools - input: url (text) -> output: tools (text)
* Lista ferramentas disponíveis no servidor.
*
* MCP.Call - inputs: url, tool, args (text) -> output: result (text)
* Chama uma ferramenta com argumentos JSON.
*
* Compilar:
* make mcp-lib
*
* Carregar no editor:
* ./build/editor build/mcp.so ou Ctrl+O -> build/mcp.so
*
* Exemplo de uso no editor:
* [Literal.Text "stdio://npx @modelcontextprotocol/server-filesystem /tmp"]
* -> [MCP.ListTools] -> [IO.Print "tools"]
*/
#define _POSIX_C_SOURCE 200809L
#include <stdlib.h>
#include <string.h>
#include <tinyblocks/tinyblocks.h>
#include <tinyblocks-mcp/tb_mcp.h>
/* -- Helper: lê texto de slot --- */
static const char* gs(TinyBlocks_Block* self, TinyBlocks* rt, uint32_t idx) {
TinyBlocks_Value v = tb_block_get_input(self, rt, idx);
return (v.kind == TB_VALUE_TEXT && v.as.text) ? v.as.text : "";
}
/* -- MCP.Ping --- */
static void eval_mcp_ping(TinyBlocks_Block* self, TinyBlocks* rt) {
const char* url = gs(self, rt, 0);
char* result = tb_mcp_ping(url);
tb_block_set_output(self, 0, tb_value_text(result ? result : "erro"));
free(result);
self->dirty = false;
}
/* -- MCP.ListTools --- */
static void eval_mcp_list_tools(TinyBlocks_Block* self, TinyBlocks* rt) {
const char* url = gs(self, rt, 0);
char* result = tb_mcp_list_tools(url);
tb_block_set_output(self, 0, tb_value_text(result ? result : "erro"));
free(result);
self->dirty = false;
}
/* -- MCP.Call --- */
static void eval_mcp_call(TinyBlocks_Block* self, TinyBlocks* rt) {
const char* url = gs(self, rt, 0);
const char* tool = gs(self, rt, 1);
const char* args = gs(self, rt, 2);
char* result = tb_mcp_call_tool(url, tool, args);
tb_block_set_output(self, 0, tb_value_text(result ? result : "erro"));
free(result);
self->dirty = false;
}
/* -- Slots --- */
static const TinyBlocks_SlotDesc url_in[] = {{"url", TB_VALUE_TEXT}};
static const TinyBlocks_SlotDesc call_in[] = {{"url", TB_VALUE_TEXT},
{"tool", TB_VALUE_TEXT},
{"args", TB_VALUE_TEXT}};
static const TinyBlocks_SlotDesc status_out[] = {{"status", TB_VALUE_TEXT}};
static const TinyBlocks_SlotDesc tools_out[] = {{"tools", TB_VALUE_TEXT}};
static const TinyBlocks_SlotDesc result_out[] = {{"result", TB_VALUE_TEXT}};
/* -- Registro --- */
static bool mcp_init(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib) {
if (!tb_mcp_init()) return false;
TinyBlocks_TypeBlock* t;
t = tb_type_block_create(rt, "MCP.Ping",
url_in, 1, status_out, 1, eval_mcp_ping);
if (t) tb_library_add(lib, &t->base);
t = tb_type_block_create(rt, "MCP.ListTools",
url_in, 1, tools_out, 1, eval_mcp_list_tools);
if (t) tb_library_add(lib, &t->base);
t = tb_type_block_create(rt, "MCP.Call",
call_in, 3, result_out, 1, eval_mcp_call);
if (t) tb_library_add(lib, &t->base);
return true;
}
static void mcp_deinit(TinyBlocks* rt, TinyBlocks_LibraryBlock* lib) {
(void)rt; (void)lib;
tb_mcp_deinit();
}
TINYBLOCKS_DEFINE_LIBRARY(mcp,
"tinyblocks-mcp",
"1.0.0",
mcp_init,
mcp_deinit)