add nodejs environment

This commit is contained in:
Syoyo Fujita
2025-07-24 07:01:38 +09:00
parent be455ebfa9
commit 4a8fbab8cb
2 changed files with 20 additions and 20 deletions

View File

@@ -89,7 +89,7 @@ endif()
# 512kB stack
# NOTE: ASYNCIFY increase the wasm size to around 4~6 MB
set(TINYUSDZ_EMCC_LINK_FLAGS "-Oz -sENVIRONMENT='web,worker' -sSTACK_SIZE=512000 -sALLOW_MEMORY_GROWTH=1 -sMODULARIZE=1 -sEXPORT_ES6 -sINVOKE_RUN=0 --bind ")
set(TINYUSDZ_EMCC_LINK_FLAGS "-Oz -sENVIRONMENT='web,worker,node' -sSTACK_SIZE=512000 -sALLOW_MEMORY_GROWTH=1 -sMODULARIZE=1 -sEXPORT_ES6 -sINVOKE_RUN=0 --bind ")
if (TINYUSDZ_WASM64)
# assertion=1 cause runtime error(Cannot mix BigInt and ... in assert()), so use 2

View File

@@ -5,7 +5,7 @@ import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/
import { isInitializeRequest } from "@modelcontextprotocol/sdk/types.js";
import { z } from "zod";
import { TinyUSDZLoader } from "tinyusdz/TinyUSDLoader.js";
//import { TinyUSDZLoader } from "tinyusdz/TinyUSDLoader.js";
const portno = 8085;
@@ -13,9 +13,9 @@ const app = express();
app.use(express.json());
// Map to store transports by session ID
const transports: { [sessionId: string]: StreamableHTTPServerTransport } = {};
const transports = {};
const session = Map();
const session = new Map();
// Handle POST requests for client-to-server communication
app.post('/mcp', async (req, res) => {
@@ -23,8 +23,9 @@ app.post('/mcp', async (req, res) => {
console.log(req.headers);
console.log(req.body);
// Check for existing session ID
const sessionId = req.headers['mcp-session-id'] as string | undefined;
let transport: StreamableHTTPServerTransport;
const sessionId = req.headers['mcp-session-id'] || undefined;
console.log("sessionId", sessionId);
let transport = null;
if (sessionId && transports[sessionId]) {
// Reuse existing transport
@@ -57,24 +58,23 @@ app.post('/mcp', async (req, res) => {
version: "1.0.0"
});
server.registerTool("version",
server.registerTool("get_version",
{
title: "Get TinyUSDZ version",
description: "Get TinyUSDZ version",
inputSchema: { }
inputSchema: {}
},
async ({ }) => {
return { content: [
{ type: 'text',
return {
content: [
{
type: 'text',
text: "v0.9.0"
}
],
})
);
],
}
});
server.registerTool("add",
{
title: "Addition Tool",
@@ -108,13 +108,13 @@ app.post('/mcp', async (req, res) => {
});
// Reusable handler for GET and DELETE requests
const handleSessionRequest = async (req: express.Request, res: express.Response) => {
const sessionId = req.headers['mcp-session-id'] as string | undefined;
const handleSessionRequest = async (req, res) => {
const sessionId = req.headers['mcp-session-id'];
if (!sessionId || !transports[sessionId]) {
res.status(400).send('Invalid or missing session ID');
return;
}
const transport = transports[sessionId];
await transport.handleRequest(req, res);
};