story-weaver-ai
Version:
A narrative development system for AI-driven storytelling with Jungian psychology
96 lines (78 loc) • 2.27 kB
JavaScript
/**
* Story Weaver MCP Server - Core
*
* @author Sean Pavlak
* @github https://github.com/seanpavlak/cursor-story-master
*/
import { FastMCP } from "fastmcp";
import path from "path";
import dotenv from "dotenv";
import { fileURLToPath } from "url";
import fs from "fs";
import logger from "./logger.js";
import { registerStoryWeaverTools } from "./tools/index.js";
// Load environment variables
dotenv.config();
// Constants
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
/**
* Main MCP server class that integrates with Story Weaver
* for narrative analysis and psychological storytelling
*/
class StoryWeaverMCPServer {
constructor() {
// Get version from package.json using synchronous fs
const packagePath = path.join(__dirname, "../../package.json");
const packageJson = JSON.parse(fs.readFileSync(packagePath, "utf8"));
this.options = {
name: "Story Weaver MCP Server",
version: packageJson.version,
description: "Narrative analysis and storytelling with Jungian psychology"
};
this.server = new FastMCP(this.options);
this.initialized = false;
// Bind methods
this.init = this.init.bind(this);
this.start = this.start.bind(this);
this.stop = this.stop.bind(this);
// Setup logging
this.logger = logger;
}
/**
* Initialize the MCP server with necessary tools and routes
* for story analysis and narrative element management
*/
async init() {
if (this.initialized) return;
// Register Story Weaver tools
registerStoryWeaverTools(this.server);
this.initialized = true;
logger.info("Story Weaver MCP Server initialized with narrative tools");
return this;
}
/**
* Start the MCP server
*/
async start() {
if (!this.initialized) {
await this.init();
}
// Start the FastMCP server
await this.server.start({
transportType: "stdio",
});
logger.info(`Story Weaver MCP Server v${this.options.version} started`);
return this;
}
/**
* Stop the MCP server
*/
async stop() {
if (this.server) {
await this.server.stop();
logger.info("Story Weaver MCP Server stopped");
}
}
}
export default StoryWeaverMCPServer;