This commit is contained in:
56
docs/snippets/c/mcp/mcp_custom_client.md
Normal file
56
docs/snippets/c/mcp/mcp_custom_client.md
Normal file
@@ -0,0 +1,56 @@
|
||||
```c title="C"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* The kreuzberg C FFI does not bundle an MCP client. Drive the kreuzberg
|
||||
* CLI's stdio MCP transport from a C host that also links libkreuzberg. */
|
||||
int main(void) {
|
||||
int request_pipe[2];
|
||||
int response_pipe[2];
|
||||
if (pipe(request_pipe) < 0 || pipe(response_pipe) < 0) {
|
||||
perror("pipe");
|
||||
return 1;
|
||||
}
|
||||
|
||||
pid_t pid = fork();
|
||||
if (pid < 0) {
|
||||
perror("fork");
|
||||
return 1;
|
||||
}
|
||||
if (pid == 0) {
|
||||
dup2(request_pipe[0], 0);
|
||||
dup2(response_pipe[1], 1);
|
||||
close(request_pipe[1]);
|
||||
close(response_pipe[0]);
|
||||
execlp("kreuzberg", "kreuzberg", "mcp", (char *)NULL);
|
||||
perror("execlp");
|
||||
_exit(127);
|
||||
}
|
||||
|
||||
close(request_pipe[0]);
|
||||
close(response_pipe[1]);
|
||||
|
||||
const char *request =
|
||||
"{\"method\":\"tools/call\","
|
||||
"\"params\":{\"name\":\"extract_file\","
|
||||
"\"arguments\":{\"path\":\"document.pdf\",\"async\":true}}}\n";
|
||||
if (write(request_pipe[1], request, strlen(request)) < 0) {
|
||||
perror("write");
|
||||
return 1;
|
||||
}
|
||||
close(request_pipe[1]);
|
||||
|
||||
char buffer[4096];
|
||||
ssize_t bytes_read = read(response_pipe[0], buffer, sizeof(buffer) - 1);
|
||||
if (bytes_read > 0) {
|
||||
buffer[bytes_read] = '\0';
|
||||
printf("%s", buffer);
|
||||
}
|
||||
close(response_pipe[0]);
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
<!-- snippet:syntax-only --> No MCP client is exposed by libkreuzberg; this snippet drives the MCP CLI over stdio.
|
||||
29
docs/snippets/c/mcp/mcp_server_start.md
Normal file
29
docs/snippets/c/mcp/mcp_server_start.md
Normal file
@@ -0,0 +1,29 @@
|
||||
```c title="C"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* The kreuzberg C FFI does not embed the MCP server. Spawn the kreuzberg
|
||||
* CLI from a host process that uses libkreuzberg for in-process extraction. */
|
||||
int main(void) {
|
||||
pid_t pid = fork();
|
||||
if (pid < 0) {
|
||||
perror("fork");
|
||||
return 1;
|
||||
}
|
||||
if (pid == 0) {
|
||||
execlp("kreuzberg", "kreuzberg", "mcp", (char *)NULL);
|
||||
perror("execlp");
|
||||
_exit(127);
|
||||
}
|
||||
|
||||
int status = 0;
|
||||
if (waitpid(pid, &status, 0) < 0) {
|
||||
perror("waitpid");
|
||||
return 1;
|
||||
}
|
||||
return WIFEXITED(status) ? WEXITSTATUS(status) : 1;
|
||||
}
|
||||
```
|
||||
|
||||
<!-- snippet:syntax-only --> The MCP server is exposed only through the kreuzberg CLI; libkreuzberg's C FFI offers no MCP entry point. This snippet spawns the CLI from a host that already links against libkreuzberg.
|
||||
Reference in New Issue
Block a user