Skip to content

Commit 7483345

Browse files
committed
fix: lazy load wrap-up content in prompt handler
1 parent 29e09ad commit 7483345

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

.changeset/loud-jobs-notice.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"ansible-database-mcp": patch
3+
---
4+
5+
lazy load wrap-up content in prompt handler

src/prompts/ask.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { z } from 'zod';
55
import { Paths } from '../config/paths.js';
66

77
let guideContent: string | undefined;
8-
let contextContent: string | undefined;
98

109
const definition: PromptDefinition = {
1110
name: 'ask',
@@ -32,26 +31,13 @@ const getGuideContent = async () => {
3231
}
3332
};
3433

35-
36-
const getContextContent = async () => {
37-
38-
if (contextContent) {
39-
return contextContent;
40-
}
41-
42-
const contextPath = Paths.getContextPath();
43-
contextContent = readFileSync(contextPath, 'utf-8');
44-
return contextContent;
45-
};
46-
47-
const handler: (question: string, useContext?: boolean) => Promise<GetPromptResult> = async (question: string, useContext?: boolean) => {
34+
const handler: (question: string, useContext?: string) => Promise<GetPromptResult> = async (question: string, useContext?: string) => {
4835
const guideContent = await getGuideContent();
4936

5037
let response = `${guideContent}\n\nQuestion: ${question}`;
5138

5239
if (useContext) {
53-
const contextContent = await getContextContent();
54-
response += `\n\nContext: ${contextContent}`;
40+
response += `\n\nContext: ${useContext}`;
5541
}
5642

5743
return {

src/prompts/wrap-up.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@ import { Paths } from "@/config/paths";
22
import { PromptDefinition } from "@/types/modelcontextprotocol";
33
import { GetPromptResult } from "@modelcontextprotocol/sdk/types";
44

5-
const wrapUpContent = Paths.getAssetsTextFile('wrap-up.md');
65

76
const definition: PromptDefinition = {
87
name: 'wrap-up',
98
description: 'Wrap up the conversation and generate a schema document'
109
};
1110

11+
let wrapUpContent: string;
12+
1213
const handler: () => Promise<GetPromptResult> = async () => {
14+
if (!wrapUpContent) {
15+
wrapUpContent = Paths.getAssetsTextFile('wrap-up.md');
16+
}
17+
1318
return {
1419
messages: [
1520
{

0 commit comments

Comments
 (0)