Skip to content

Instantly share code, notes, and snippets.

@chunhualiao
Last active November 14, 2025 21:25
Show Gist options
  • Select an option

  • Save chunhualiao/cc8c5b9933e06fa4125fc5bf1dab5d2a to your computer and use it in GitHub Desktop.

Select an option

Save chunhualiao/cc8c5b9933e06fa4125fc5bf1dab5d2a to your computer and use it in GitHub Desktop.
test Deepwiki MCP server

The official doc at https://docs.devin.ai/work-with-devin/deepwiki-mcp is incomplete, letting readers wonder about how exactly to use it.

Found an example from https://platform.openai.com/docs/guides/tools-connectors-mcp

It seems like one just put the github repo id (such as accountID/repoID or rose-compiler/rose-full) into the question, then deepwiki will answer question about that repo.

from openai import OpenAI
import os
import sys

api_key = os.getenv("OPENAI_API_KEY")
if not api_key:
    print("OPENAI_API_KEY is not set. Please export it in your environment.")
    sys.exit(0)

client = OpenAI(api_key=api_key)

question1="What header and source files are used to define Sawyer in (rose-compiler/rose-full) ?"

question2="What transport protocols does the 2025-03-26 version of the MCP spec (modelcontextprotocol/modelcontextprotocol) support?"

resp = client.responses.create(
    model="gpt-5",
    tools=[
        {
            "type": "mcp",
            "server_label": "deepwiki",
            "server_url": "https://mcp.deepwiki.com/mcp",
            "require_approval": {
                "never": {
                    "tool_names": ["ask_question", "read_wiki_structure"]
                }
            }
        },
    ],
    input=question1,
)

print(resp.output_text)
@chunhualiao
Copy link
Author

chunhualiao commented Nov 14, 2025

execution results:

python mcp-server.py 
- Header: src/Sawyer/Sawyer.h
- Core source: src/Sawyer/Sawyer.C

Note: The Sawyer library’s implementation is spread across multiple source files listed in src/Sawyer/CMakeLists.txt (e.g., Assert.C, Attribute.C, CommandLine.C, Message.C, Synchronization.C, Time.C, Yaml.C, etc.).

Different runs may generate different results,

python mcp-server.py 
According to src/Sawyer/CMakeLists.txt in rose-compiler/rose-full, Sawyer is defined by these files:

Source files (.C)
- src/Sawyer/Assert.C
- src/Sawyer/Attribute.C
- src/Sawyer/Clexer.C
- src/Sawyer/CommandLine.C
- src/Sawyer/CommandLineBoost.C
- src/Sawyer/DocumentBaseMarkup.C
- src/Sawyer/RoseDatabase.C
- src/Sawyer/DocumentMarkup.C
- src/Sawyer/DocumentPodMarkup.C
- src/Sawyer/DocumentTextMarkup.C
- src/Sawyer/GraphTraversal.C
- src/Sawyer/LineVector.C
- src/Sawyer/Message.C
- src/Sawyer/ProgressBar.C
- src/Sawyer/Sawyer.C
- src/Sawyer/SmallObject.C
- src/Sawyer/Stopwatch.C
- src/Sawyer/Synchronization.C
- src/Sawyer/Time.C
- src/Sawyer/Yaml.C

Header files (.h)
- src/Sawyer/Access.h
- src/Sawyer/AddressMap.h
- src/Sawyer/AddressSegment.h
- src/Sawyer/AllocatingBuffer.h
- src/Sawyer/Assert.h
- src/Sawyer/Attribute.h
- src/Sawyer/BiMap.h
- src/Sawyer/BitFlags.h
- src/Sawyer/BitVector.h
- src/Sawyer/BitVectorSupport.h
- src/Sawyer/Buffer.h
- src/Sawyer/Cached.h
- src/Sawyer/Callbacks.h
- src/Sawyer/Clexer.h
- src/Sawyer/CommandLine.h
- src/Sawyer/CommandLineBoost.h
- src/Sawyer/Database.h
- src/Sawyer/DatabasePostgresql.h
- src/Sawyer/DatabaseSqlite.h
- src/Sawyer/DefaultAllocator.h
- src/Sawyer/DenseIntegerSet.h
- src/Sawyer/DistinctList.h
- src/Sawyer/DocumentBaseMarkup.h
- src/Sawyer/DocumentMarkup.h
- src/Sawyer/DocumentPodMarkup.h
- src/Sawyer/DocumentTextMarkup.h
- src/Sawyer/Exception.h
- src/Sawyer/FileSystem.h
- src/Sawyer/Graph.h
- src/Sawyer/GraphAlgorithm.h
- src/Sawyer/GraphBoost.h
- src/Sawyer/GraphIteratorBiMap.h
- src/Sawyer/GraphIteratorMap.h
- src/Sawyer/GraphIteratorSet.h
- src/Sawyer/GraphTraversal.h
- src/Sawyer/IndexedList.h
- src/Sawyer/Interval.h
- src/Sawyer/IntervalMap.h
- src/Sawyer/IntervalSet.h
- src/Sawyer/IntervalSetMap.h
- src/Sawyer/HashMap.h
- src/Sawyer/Lexer.h
- src/Sawyer/LineVector.h
- src/Sawyer/Map.h
- src/Sawyer/MappedBuffer.h
- src/Sawyer/Message.h
- src/Sawyer/NullBuffer.h
- src/Sawyer/Optional.h
- src/Sawyer/Parse.h
- src/Sawyer/PoolAllocator.h
- src/Sawyer/ProgressBar.h
- src/Sawyer/Sawyer.h
- src/Sawyer/Set.h
- src/Sawyer/SharedObject.h
- src/Sawyer/Result.h
- src/Sawyer/SharedPointer.h
- src/Sawyer/SmallObject.h
- src/Sawyer/Stack.h
- src/Sawyer/StackAllocator.h
- src/Sawyer/StaticBuffer.h
- src/Sawyer/Stopwatch.h
- src/Sawyer/Synchronization.h
- src/Sawyer/ThreadWorkers.h
- src/Sawyer/Time.h
- src/Sawyer/PartialResult.h
- src/Sawyer/Trace.h
- src/Sawyer/Tracker.h
- src/Sawyer/Tree.h

Note: src/Sawyer/Sawyer.h is the main umbrella header; the implementations are spread across the .C files above.

compared to web interface used to ask the same question. The web interface responds with much more details answer:

https://deepwiki.com/search/what-header-and-source-files-a_734bbdd6-16b1-47b1-85b9-ea79bae8124e?mode=fast

@chunhualiao
Copy link
Author

chunhualiao commented Nov 14, 2025

How to configure deepwiki MCP server with Cline?

The chat window of Cline's bottom has a series of icons. One of them (three bricks) is to configure MCP .

Screenshot 2025-11-14 at 11 47 42 AM Screenshot 2025-11-14 at 11 48 16 AM

Prompts in Cline

Now, with MCP server enabled, you can pose questions like the following (mention the github repo ID using accountID/repoID form)

find me an example in rose-compiler/rose-full about how to create a statement like int i;

Cline will figure out this should be handled by the deepwiki MCP server, ask for your permission to use it, then route the question/answer for you.

The raw response from the MCP server within Cline:

To create a variable declaration statement like int i; using the ROSE compiler framework API, you should use the SageBuilder::buildVariableDeclaration function. This function is part of the high-level AST construction interface provided by SageBuilder and SageInterface namespaces.

The buildVariableDeclaration function handles the creation of the SgVariableDeclaration node, along with associated symbol table entries and source file position information, transparently.

Here's how you would typically use it:

SgName name("i");
SgType* type = SageBuilder::buildIntType(); // Assuming you want an 'int' type
SgScopeStatement* scope = ...; // The scope where the variable should be declared

SgVariableDeclaration* varDecl = SageBuilder::buildVariableDeclaration(name, type, NULL, scope);

The buildVariableDeclaration function has several overloads, allowing you to specify the variable name as SgName, std::string, or const char*. It also takes an optional SgInitializer for cases where the variable is initialized at declaration.

After building the SgVariableDeclaration node, you would typically insert it into the AST using functions like SageInterface::appendStatement(), prependStatement(), or insertStatement(). These functions ensure that all necessary side effects for symbol tables, source file information, scope, and parent pointers are handled correctly.

For example, to insert the declaration into a scope:

SageInterface::appendStatement(varDecl, scope);

The internal implementation of buildVariableDeclaration creates a new SgVariableDeclaration object and sets its firstNondefiningDeclaration to itself. It also handles the creation of SgInitializedName objects and their association with the declaration. If a scope is provided, it will attempt to fix the variable declaration within that scope, which includes managing symbol tables.

Notes:
The buildVariableDeclaration_nfi function is a "non-file-info" version, which is used internally and might have specific use cases related to how file information is handled or when reusing existing SgInitializedName objects. For general use, buildVariableDeclaration is recommended.

Wiki pages you might want to explore:

View this search on DeepWiki: https://deepwiki.com/search/how-to-create-a-variable-decla_8b406500-10f2-4111-8fef-ee66e777594a

Cline further summarized it to be more brief

Thinking:The MCP tool returned a good example. It shows how to create a variable declaration like "int i;" using SageBuilder::buildVariableDeclaration. ‎

To create a variable declaration statement like int i; in the ROSE compiler framework, use the SageBuilder::buildVariableDeclaration function from the high-level AST construction interface. Here's an example:

SgName name("i");
SgType* type = SageBuilder::buildIntType();
SgScopeStatement* scope = ...; // The scope where the variable should be declared

SgVariableDeclaration* varDecl = SageBuilder::buildVariableDeclaration(name, type, NULL, scope);

After creating the declaration, insert it into the AST using functions like SageInterface::appendStatement():

SageInterface::appendStatement(varDecl, scope);

This handles creating the SgVariableDeclaration node, symbol table entries, and source file position information automatically. The function has overloads for different name types and supports optional initializers.

@chunhualiao
Copy link
Author

Cline's MCP server configuration tab exposes the tool details of DeepWiki

Screenshot 2025-11-14 at 12 00 23 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment