Skip to content

Commit 7486b2c

Browse files
authored
streamable http default (#20)
* streamable http by default, make openai throw error rather than fail Signed-off-by: Eitan Yarmush <[email protected]> * allow for strict mode Signed-off-by: Eitan Yarmush <[email protected]> --------- Signed-off-by: Eitan Yarmush <[email protected]>
1 parent 90216ff commit 7486b2c

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

mcp/src/index.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ const __dirname = path.dirname(__filename);
2424
const openAIApiKey = process.env.OPENAI_API_KEY;
2525
const dbDir = process.env.SQLITE_DB_DIR || __dirname; // Default to current dir if not set
2626

27-
if (!openAIApiKey) {
28-
console.error("Error: OPENAI_API_KEY environment variable is not set.");
29-
process.exit(1);
30-
}
3127
if (!fs.existsSync(dbDir)) {
3228
console.warn(`Warning: SQLITE_DB_DIR (${dbDir}) does not exist. Databases may not be found.`);
3329
process.exit(1);
3430
}
3531

36-
const openai = new OpenAI({
37-
apiKey: openAIApiKey,
38-
});
32+
const strictMode = process.env.STRICT_MODE === 'true';
33+
if (strictMode) {
34+
if (!openAIApiKey) {
35+
console.error("Error: OPENAI_API_KEY environment variable is not set.");
36+
process.exit(1);
37+
}
38+
}
3939

4040
export interface QueryResult {
4141
chunk_id: string;
@@ -48,6 +48,9 @@ export interface QueryResult {
4848

4949
async function createEmbeddings(text: string): Promise<number[]> {
5050
try {
51+
const openai = new OpenAI({
52+
apiKey: openAIApiKey,
53+
});
5154
console.error("Calling OpenAI embeddings API...");
5255
const startTime = Date.now();
5356
const response = await openai.embeddings.create({
@@ -189,7 +192,7 @@ server.tool(
189192

190193
// --- Transport Setup ---
191194
async function main() {
192-
const transport_type = process.env.TRANSPORT_TYPE || 'sse';
195+
const transport_type = process.env.TRANSPORT_TYPE || 'http';
193196

194197
if (transport_type === 'stdio') {
195198
// Stdio transport for direct communication

0 commit comments

Comments
 (0)