Editor como servidor MCP: agentes leem e editam as pilhas por código
tinyblocks-mcp-server (C, sem Python): servidor MCP nas duas eras do protocolo. Moderna (2026-07-28): sem handshake, versão e capacidades em _meta a cada pedido, server/discover, resultType, cabeçalhos MCP-Protocol-Version/Mcp-Method/Mcp-Name conferidos com o corpo (HeaderMismatch, UnsupportedProtocolVersion). Antiga: initialize. HTTP só em 127.0.0.1 (Origin conferido, GET/DELETE 405, sem sessão), sem bloquear (o editor atende a cada quadro), e stdio. test-mcp-server. Ferramentas do editor (tb_editor_mcp.c; http://127.0.0.1:7811/mcp, TINYBLOCKS_MCP_PORT muda a porta, 0 = sem rede): get_editor, list_block_types, list_stacks (scratchblocks + ids dos blocos), get_scratchblocks, add_scratchblocks, replace_stack, move_stack, delete_stack, add_block / move_block (solto, embaixo, num campo ou numa boca; alone = só o bloco) / delete_block / set_inputs, run / stop / get_output, new_tab / select_tab, save_project / open_project e ui_tree / ui_action / ui_type (a interface pela árvore acessível). O editor exporta e importa scratchblocks por pilha (numa aba existente, numa posição), e o modelo de blocos fica na API privada para o servidor. O scratchblocks usa também os rótulos declarados pelas libraries. Duplicar um bloco C de três bocas copiava só duas. O cliente (tinyblocks-mcp) fala as duas eras: sonda com server/discover no stdio, pedido moderno no HTTP, e cai para o initialize com servidores antigos. test-mcp testa contra o servidor antigo de teste e contra o moderno (stdio e HTTP); harness cenário 29 usa as ferramentas do editor. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
10a8099c46
commit
2a2d22a64a
19 files changed
+2669
-116
No files matched your search
@@ -973,6 +973,9 @@ typedef struct Ed {
|
||||
TinyBlocks_A11yTree* ax_tree;
|
||||
bool ax_enabled; /* TINYBLOCKS_A11Y=0 desliga */
|
||||
bool ax_on; /* montando a arvore neste desenho */
|
||||
|
||||
/* Servidor MCP: agentes leem e editam as pilhas por ferramentas */
|
||||
struct TbMcpServer* mcp;
|
||||
} Ed;
|
||||
|
||||
static inline TinyBlocks_A11yTree* ed_ax(Ed* ed) { return ed->ax_on ? ed->ax_tree : NULL; }
|
||||
@@ -1026,6 +1029,54 @@ typedef struct TabClass {
|
||||
} TabClass;
|
||||
|
||||
const TabClass* tab_class(const Tab* T);
|
||||
|
||||
/* == Modelo de blocos (tb_editor.c), usado tambem pelo servidor MCP ===
|
||||
* Indices de bloco sao posicoes no pool da aba (T->ws); "pilha" = bloco de
|
||||
* topo (T->top). Mudou a aba: layout_tab(T). */
|
||||
int blk_new(Tab* T, TinyBlocks_TypeBlock* type);
|
||||
void top_add(Tab* T, int bi);
|
||||
void top_remove(Tab* T, int bi);
|
||||
void blk_link(Tab* T, int parent, int rel, int child);
|
||||
void detach(Tab* T, int bi); /* vira pilha, com os de baixo */
|
||||
void attach_insert(Tab* T, int parent, int rel, int bi); /* pilha bi em parent/rel */
|
||||
void attach_arg(Tab* T, int parent, int s, int bi); /* reporter bi no campo s */
|
||||
int chain_last(Tab* T, int bi);
|
||||
int stack_root(Tab* T, int bi);
|
||||
void free_tree(Ed* ed, Tab* T, int bi); /* bi, o encaixado e os de baixo */
|
||||
void delete_heal(Ed* ed, Tab* T, int bi); /* so bi; os de baixo sobem */
|
||||
void layout_tab(Tab* T);
|
||||
void stack_bounds(Tab* T, int root, float* x0, float* y0, float* x1, float* y1);
|
||||
void cleanup_ws(Ed* ed);
|
||||
Shape shape_of(const TinyBlocks_TypeBlock* t);
|
||||
bool shape_is_value(Shape s);
|
||||
int shape_mouths(Shape s);
|
||||
bool is_cap(const TinyBlocks_TypeBlock* t);
|
||||
const char* mouth_label(const TinyBlocks_TypeBlock* t, int k);
|
||||
int input_count(const TinyBlocks_TypeBlock* t);
|
||||
bool slot_is_bool(const TinyBlocks_TypeBlock* t, int i);
|
||||
const char* slot_src(const EdBlock* b, int s);
|
||||
int cat_of(Ed* ed, const char* type_name);
|
||||
const BlockSpec* spec_of_type(const TinyBlocks_TypeBlock* t);
|
||||
void ax_block_label(Tab* T, int bi, char* out, size_t cap, int depth); /* "repita (10) vezes" */
|
||||
void tab_select(Ed* ed, int i);
|
||||
void run_flag(Ed* ed);
|
||||
void run_click(Ed* ed, int bi); /* na aba atual */
|
||||
void vm_stop(Ed* ed);
|
||||
bool project_load(Ed* ed, const char* path);
|
||||
bool project_save(Ed* ed, const char* path);
|
||||
/* scratchblocks: pilha head (head < 0 = aba inteira) -> texto (malloc) */
|
||||
char* ed_scratchblocks_export(Ed* ed, const Tab* T, int head);
|
||||
/* texto -> pilhas novas na aba T a partir de (x, y); devolve quantas (-1 = nenhuma) */
|
||||
int ed_scratchblocks_import(Ed* ed, Tab* T, const char* text, float x, float y,
|
||||
int* heads, int max, char* warn, size_t warn_cap);
|
||||
|
||||
void ed_type_text(Ed* ed, const char* text); /* como digitar no teclado */
|
||||
void ed_press_key(Ed* ed, int scancode);
|
||||
|
||||
/* == Servidor MCP do editor (tb_editor_mcp.c) == */
|
||||
void ed_mcp_start(Ed* ed); /* TINYBLOCKS_MCP_PORT (0 = desliga) */
|
||||
void ed_mcp_poll(Ed* ed); /* a cada quadro */
|
||||
void ed_mcp_stop(Ed* ed);
|
||||
bool tab_has_define(const Tab* T);
|
||||
bool tab_has_define(const Tab* T);
|
||||
void tab_doc_free(Tab* T);
|
||||
|
||||
Reference in new issue
Block a user